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.

Recommended Answers

All 9 Replies

Do you have any specific java programming questions? or problems? Post them.

I already did if you look back or open the attached file, would should be able to see it. It consist of a list within another list.
Name of tlist:First_list
Name of list:another_List
Name of list:The_last_one

Thx

OK, if you've solved this, then mark it as solved.
If you want any help, explain your problem.
Post all your questions here on the forum.
No attachments.

here it is:
Main:
if call a firstlist (y)
enter list (val)
add number
if (y) call number
ad list_last_one (y)
Enter list (val)
add number
if Call (n)
display
exit

What did you post just now?
Is that what the program outputs now?
Can you add some comments that explains what is wrong with that output and that shows what the output should be.

What you posted looks like pseudo code? Can you explain?

Yes, that is exactely a pseudocode, and I need the program that give that type of result.Then,create lists from this class using two different classes for the type parameter creating a "list of lists". where 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:

I need the program that give that type of result.

If you have any specific questions about the program, ask them.

Have you written any code for this problem? Post some code with your questions if you want any help.

Member Avatar for ztini

I need the program that give that type of result.

So get to coding.

Thread closed since no attempt on solving from OP. Forum rules clearly state

Do provide evidence of having done some work yourself if posting questions from school or work assignments

So start working on and create new thread as this is closed now for any further discussion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.