Thread: Pointers
View Single Post
Old 03-02-2003, 11:44 AM   #14 (permalink)
carrja99
Registered User
 
Join Date: Feb 2003
Posts: 34
carrja99 is on a distinguished road
Oh! Are you trying to keep track of the previous node? for example:

Code:
[]->[]->[]->[]->[]
         ^   ^
         |   |
       prev  current
in that case, there are several ways you could achieve this, the easiest being to use two pointers, one pointing to a current (but considered previous) node, and the other pointing to next. As for insertion and deletion, it's fairly easy.

the basis for insertion is to create a new node, then traverse the list till you find a node whose node->next is greater than the node you want to insert. you then woulld connect your newnode to the next node, and connect the current to the new node.

as for deletion, you simply need to make a copy of the link from the deleted node, example;
Code:
tmp = deletednode->next;
delete deletednode;
currentNode->next = tmp;
carrja99 is offline   Reply With Quote