I did it but I got different outcome?? This program is an exercise in generic (singly) linked lists. A parameterized list class with just a few operations. Then,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:
add a list (y/n)? y
name of list? first_list
add a number (y/n)? y
value: 10
add a number (y/n)? y
value: 11
add a number (y/n)? y
value: 12
add a number (y/n)? n
add a list (y/n)? y
name of list? another_list
add a number (y/n)? n
add a list (y/n)? y
name of list? the_last_one
add a number (y/n)? y
value: -1
add a number (y/n)? y
value: -2
add a number (y/n)? y
value: -3
add a number (y/n)? y
value: -4
add a number (y/n)? n
add a list (y/n)? n
list name: first_list
10
11
12
list name: another_list
list name: the_last_one
-1
-2
-3
-4GList<T> will have two (private, of course) fields, both of type GNode<T>: head and cursor. The head field will simply be a head pointer for the linked list. The cursor field will be used to point to nodes in the list. The (only) public methods in this class are:
-public void insertFirst(T t): puts a new node containing t as a new first element of the list and makes cursor point to this node.
-public void insertNext(T t): puts a new node containing t into the list after the node pointed to by cursor and makes cursor point to this node.
-public T getFirstItem(): points cursor to the first node and returns the value stored in that node.
-public T getNextItem(): advances cursor one place in the list and returns the value stored at that node.
-public boolean hasNextItem(): returns whether or not the node pointed to by cursor is followed by another node.