502 Week 2
On line 232, the new node is set to point to the node currently pointed to by pHead. Note
that this does not point the new node to pHead, but rather to the node to which pHeadwas
pointing! On line 233,pHeadis set to point to the new node.
The third time through the loop, the user enters the part number 4499 for a Carwith
model year 94. The counter is incremented and the number this time is not less than the
number pointed to by pHead, so the forloop that begins on line 237 is entered.
The value pointed to by pHeadis 378. The value pointed to by the second node is 2837.
The current value is 4499. The pointer pCurrentpoints to the same node as pHeadand so
has a next value; pCurrentpoints to the second node, and so the test on line 240 fails.
The pointer pCurrentis set to point to the next node and the loop repeats. This time, the
test on line 240 succeeds. There is no next item, so the current node is told to point to
the new node on line 242, and the insert is finished.
The fourth time through, the part number 3000 is entered. This proceeds just like the pre-
vious iteration, but this time when the current node is pointing to 2837 and the next node
has 4499 , the test on line 250 returns TRUEand the new node is inserted into position.
When the user finally presses 0, the test on line 275 evaluates true and the whileloop
breaks. Execution falls to line 296 where Iterate()is called, branching to line 202
where on line 208 the PNodeis used to access the Partand the Display()method is
called on that Partobject.
19 0672327112_w2_wir.qxd 11/19/04 12:28 PM Page 502