|
|
|
|  |
|
|
|
|
The link member of *newNodePtr now points to the first node in the list. |
|
|
|
| | |  |
|
|
|
|
The external pointer to the list now points to the node containing the new component. |
|
|
|
| |
|
|
|
|
|
|
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: |
|
|
|
|
|