|
|
|
|
|
|
|
// Postcondition:
// item == component member of first list node at entry
// && Node containing item is removed from linked list
// && component members of list nodes are in ascending order
{
NodePtr tempPtr = head; // Temporary pointer
item = head->component;
head = head->link;
delete tempPtr;
} |
|
|
|
|
|
|
|
|
We don't show a complete code walk-through because the code is so straightforward. Instead, we show the state of the data structure in two stages: after the first two statements and at the end. We use one of our previous lists. Following is the data structure after the execution of the first two statements in the function. |
|
|
|
|
|
|
|
|
After the execution of the function, the structure is as follows: |
|
|
|
|
|
|
|
|
The function for deleting a node whose component contains a certain value is similar to the Insert function. The difference is that we are looking for a match, not a component member greater than our item. If we use a pre- |
|
|
|
|
|