Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused with linked list

 
Xiao Ping Xiao Ping
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic