February 2014
Beginner
1248 pages
62h 25m
English
Now we discuss each method of class List (Fig. 21.3) in detail and provide diagrams showing the reference manipulations performed by methods insertAtFront, insertAtBack, removeFromFront and removeFromBack. Method insertAtFront (lines 60–66 of Fig. 21.3) places a new node at the front of the list. The steps are:
1. Call isEmpty to determine whether the list is empty (line 62).
2. If the list is empty, assign to firstNode and lastNode the new ListNode that was initialized with insertItem (line 63). (Recall that assignment operators evaluate right to left.) The ListNode constructor at lines 13–16 calls the ListNode constructor at lines 20–24 to set instance variable data to refer to the insertItem passed as an ...
Read now
Unlock full access