160 likes | 252 Views
Figure 13.1 Trace of a binary search for 78 in the data entry. Figure 13.2 Merging two sorted arrays. 124. 37. 45. null. Figure 13.3 A linked list. 124. 37. 45. null. 40. Figure 13.4 Adding 40 to the linked list of Figure 13.3. public LinkedList()
E N D
Figure 13.1 Trace of a binary search for 78 in the data entry
124 37 45 null Figure 13.3 A linked list
124 37 45 null 40 Figure 13.4 Adding 40 to the linked list of Figure 13.3
public LinkedList() Constructs an empty linked list, with the head, previous, and current nodes null. public boolean isEmplty() Returns true if the list is empty and false otherwise. public void insert(Object o) Creates a node containing the object o, inserting it before the current element. public void remove() Removes the current element. public Object getData() Gets the data field from the current element. Returns null if the current element is null. public boolean atEnd() Returns true if the current element is null and false otherwise. public void advance() If current is not null, advances the precious and current references. public void reset() Resets the current reference to refer to the head of the list. public void display() Prints each element of the list on a separate line. Figure 13.5 The operation of LinkedList class
15 7 12 top Figure 13.6 A stack growing from left to right
top Figure 13.7 An empty stack
15 7 12 4 5 24 top Figure 13.8 A full stack
15 7 12 4 top Figure 13.9 Pushing 4 into the stack of Figure 13.6
15 7 12 4 top Figure 13.10 Popping the stack of Figure 13.9
4 17 6 back front Figure 13.12 A queue containing three elements
4 17 back 6 front Figure 13.13 A circular queue