This program is an exercise in generic (singly) linked lists. You will write a parameterized list class with just a few operations. Then you will create lists from this class using two different classes for the type parameter creating a "list of lists". You will write a driver program which will create and display a list of lists. Each (inner) list will have a name and contain integers. Running the program may look like: See image.
Your program will have three classes: GList, Header, and a main class. The Header class is used to store a String (as a name for an inner list) and an instance of GList, for an inner list of integers. In your main class then you will create an (outer) list of Header.
This class will have an inner GNode > class with a data field of type T and a next field for linking, a constructor (taking a T parameter to initialize the data field) and get and set methods for both fields. You may use the GNode class which we wrote in class for this.
GList will have two (private, of course) fields, both of type GNode >: head and cursor. The headfield will simply be a head pointer for the linked list. The cursorfield will be used to point to nodes in the list. The (only) public methods in this class are:
A list can then be traversed by methods outside of the GNode class by first calling getFirstItem() once and then calling getNextItem() while hasNextItem() returnstrue. A linked list can be built in a similar manner using insertFirst(T t) and insertNext(T t).
This class is: See image.
Notice that the type passed for the type parameter is Integer. Integer is the wrapper class for int. It must be used to store integers since int is a primary type and we can only store classes in a parameterized class. Because of "auto-boxing" and "auto-unboxing" you can assign int values to Integerand read Integer values as ints.
You can now make lists of (inner) lists where each inner list has a name by creating a list of type GList.
In your main you will create GList