< previous page page_1070 next page >

Page 1070
Insert(20)
newNodePtr = new NodeType;
newNodePtr->component = item;
prevPtr = NULL;
currPtr = head;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
These four statements initialize the variables used in the searching process. The variables and their contents are shown below.
1070-01.gif
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
while (currPtr != NULL &&
item > currPtr->component)


newNodePtr->link = currPtr;


if (prevPtr == NULL)
head = newNodePtr;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Because 20 is less than 30, the expression is FALSE and the loop body is not entered.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
link member of *newNodePtr now points to *currPtr.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Because prevPtr is NULL, the then-clause is executed and 20 is inserted at the top of the list.
1070-02.gif

 
< previous page page_1070 next page >