p = p.getNext();
The variable p
can point to any Node
.
The statement...
p = p.getNext();
...does this:
Step 1: evaluate the right hand sidep.getNext()
evaluates to the pointer contained in theNode
thatp
currently points to.
Step 2:p =
that pointer is copied intop
. Nowp
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.
Now p
is pointing at the second Node
(the one holding 493).
What would the following statement do?
p = p.getNext();