jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Confused with linked list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Confused with linked list" Watch "Confused with linked list" New topic
Author

Confused with linked list

Xiao Ping Xiao Ping
Greenhorn

Joined: Jan 29, 2005
Posts: 1
Can anyone please translate these codes below in plain english? i got really stuck in the copyTail=copTail.link problem. Please help!Thx so much!

public PolyNode listCopy(PolyNode source)
{
PolyNode copyHead;
PolyNode copyTail;
if(source==null)
return null;
copyHead=new PolyNode(source.data,source.exp,null);
copyTail=copyHead;

while(source.link!=null)
{
source=source.link;
copyTail.addPolyNodeAfter(source.data,source.exp);
copyTail=copyTail.link;
}
return copyHead;
}
The addPolyNodeAfter method:

public void addPolyNodeAfter(double element, double exp)
{
link=new PolyNode(element,exp,link);
}
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
What part do you find confusing? The basics of linked lists or the purpose and result of this particular method? I don't want to give away exactly what it does, cause figuring that out will be the fun part for you.

At the risk of stepping too far back into the basics, a linked list is a chain of "node" objects. Each one has a link to the next one in the chain, except for the last one which usually has an empty (null) link. You can start from the head node and follow the links to the next one in the chain over and over until you hit the end.

How much have you figured out so far?

Oh, and I always try to give a smiley for new first posts! Welcome aboard!
[ January 29, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Don't get me started about those stupid light bulbs.
 
subject: Confused with linked list
 
Similar Threads
Digital signature in SOAP XML
Implementation of SLR parser
Polynomial LinkedList from Text File (Modification)
(Inheritance) please Help!
Generating Random operators for an array of operands