hey guys!! can you help me with this??

Reply

Join Date: Dec 2007
Posts: 5
Reputation: reiyn17 is an unknown quantity at this point 
Solved Threads: 0
reiyn17 reiyn17 is offline Offline
Newbie Poster

hey guys!! can you help me with this??

 
0
  #1
Feb 4th, 2008
hey guys.. can you help me explain this code?
[code]
public Boolean insertAfter (double key, double dd)
{
Link current = first1
while (current.dData != key)
{
current = current.next;
if (current == null)
Return false;
}
Link newLink = new Link(dd);
if (current == last)
{
newLink.next = null;
last = newLink;
}
else
{
newLink.next = current.next;
current.next.previous = newLink;
}
newLink.previous = current;
current.next = newLink;
return true;
}

thanks!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 18
Reputation: orcboyx is an unknown quantity at this point 
Solved Threads: 0
orcboyx orcboyx is offline Offline
Newbie Poster

Re: hey guys!! can you help me with this??

 
0
  #2
Feb 4th, 2008
What is this program trying to do? Or do you have no idea at all?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: missileh is an unknown quantity at this point 
Solved Threads: 0
missileh missileh is offline Offline
Newbie Poster

Re: hey guys!! can you help me with this??

 
0
  #3
Feb 4th, 2008
/*This is a method that inserts a new node in a Doubly linked-list. It inserts a new node after a node whose data value is passed as key into the method. the second argument, dd takes the data value of the node to be inserted. It returns true if the insertion is successful. It returns false if there's no node in the list whose data value is equal to key value.*/
public Boolean insertAfter (double key, double dd)
{
Link current = first1
/*first1 is the global reference that refers the first node of the linked list. We create a reference (of class Link) that helps us traverse the linked list upto the node in which our key value is stored.*/
while (current.dData != key)
{
current = current.next;
if (current == null)
Return false;
}

/*The above while loop searches for a node whose data field holds the same value as key. If the data value of current node is not equal to key then current will move to the next node (current = current.next. If there is no next node (if current==null) then it means that we have reached the end of the linked list and no node having data value as the key value provided was found. So we return false.*/

Link newLink = new Link(dd);
/* If node with data value equal to key value is found then we have to insert a new node after this node. so creating a new node with data dd. */
if (current == last)
{
newLink.next = null;
last = newLink;
/* If current node is the last node then the next of the new node should be null. and last should now refer to the newly inserted node. */
}
else
{
newLink.next = current.next;
current.next.previous = newLink;
/* If current node is not the last node of the list then current's next node becomes new node's next (newLink.next = current.next and next node's previous refers to the newly created node (current.next.previous = newLink. */
}
newLink.previous = current;
/* now, new node's previous should be current (because we insert the new node after the node refered by current. */
current.next = newLink;
/* Finally, current node's next should refer to the newly created node. */
return true;
/* Return true to indicate successful insertion. */
}

I would suggest you try to understand linked-lists diagrammatically. Draw block diagrams in which links are drawn as arrows. Then, try to understand how the arrows will change after executing each line of code. It will be much easier to understand it that way. Ok then, Good bye. Take care!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: missileh is an unknown quantity at this point 
Solved Threads: 0
missileh missileh is offline Offline
Newbie Poster

Re: hey guys!! can you help me with this??

 
0
  #4
Feb 4th, 2008
Sorry. ) and ; are together taken as smiley in my above reply.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,355
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: hey guys!! can you help me with this??

 
0
  #5
Feb 4th, 2008
Originally Posted by missileh View Post
Sorry. ) and ; are together taken as smiley in my above reply.
Use code tags, and that won't happen.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 5
Reputation: reiyn17 is an unknown quantity at this point 
Solved Threads: 0
reiyn17 reiyn17 is offline Offline
Newbie Poster

Re: hey guys!! can you help me with this??

 
0
  #6
Feb 4th, 2008
i have no idea at all...my prof. just give us the program. she didn't explain what we'll do it..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC