If the list is empty, headPtr
contains null
and traverse()
will immediately return to its caller.
Here is traverse()
public void traverse() { Node p = headPtr; while ( p != null ) { System.out.print( p ); p = p.getNext(); } }
Here is a non-empty list:
The node pointer p
is advanced through the list until it reaches the last one.
Will traverse()
print out the last Node
?