Java Reference
In-Depth Information
data
3
next
data
5
next
data
2
next
/
list
current
After execution of the statement current = current.next , the linked list would
look like this:
data
3
next
data
5
next
data
2
next
/
list
current
Either way of thinking about this scenario works. Because in this new situation the
variable current is not null , you once again enter the loop, print out current.data
(which is now 5 ), and move current along again:
data
3
next
data
5
next
data
2
next
/
list
current
Once again current is not null , so you enter the loop a third time, print the value
of current.data ( 2 ), and reset current . But this time current.next has the value
null , so when you reset current , the computer's memory will look like this:
data
3
next
data
5
next
data
2
next
/
list
current
/
Because current has become null , when you break out of the loop the program
has produced the following output:
3
5
2
Search WWH ::




Custom Search