go to previous page   go to home page   go to next page highlighting

Answer:

p = p.getNext();

Advancing the Pointer

The variable p can point to any Node. The statement...

 p = p.getNext();

...does this:

Step 1:  evaluate the right hand side
         p.getNext() evaluates to the pointer contained in the  
         Node that p currently points to.
Step 2: p = that pointer is copied into p. Now p points to the second node.

The picture shows this.

This operation, moving a pointer from one Node to the next in a chain of Nodes is a common operation in data structures. It is called advancing the pointer.

advancing the pointer

QUESTION 7:

Now p is pointing at the second Node (the one holding 493). What would the following statement do?

 p = p.getNext();

go to previous page   go to home page   go to next page