February 2014
Beginner
1248 pages
62h 25m
English
Method print (lines 127–146 of Fig. 21.3) first determines whether the list is empty (lines 129–133). If so, print displays a message indicating that the list is empty and returns control to the calling method. Otherwise, print outputs the list’s data. Line 136 creates ListNode current and initializes it with firstNode. While current is not null, there are more items in the list. Therefore, line 141 outputs a string representation of current.data. Line 142 moves to the next node in the list by assigning the value of reference current.nextNode to current. This printing algorithm is identical for linked lists, stacks and queues.
Read now
Unlock full access