< previous page page_1067 next page >

Page 1067
newNodePtr->link = head;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The link member of *newNodePtr now points to the first node in the list.
1067-01.gif
head = newNodePtr;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The external pointer to the list now points to the node containing the new component.
1067-02.gif

To insert a component into its proper place in an ordered list, we have to loop through the nodes until we find where the component belongs. Because the OrdList class keeps components in ascending order, we can recognize where a component belongs by finding the node that contains a value greater than the one being inserted. Our new node should be inserted directly before the node with that value; therefore, we must keep track of the node before the current one in order to insert our new node. We use a pointer prevPtr to point to this previous node. This method leads to the following algorithm:

 
< previous page page_1067 next page >