
14.8 Sorted Linked Lists 1061
TABLE 14.8 Array Versus Linked List Implementation of a Stack or a Queue
Array Linked List
Easily expanded No Yes
Direct access to every item Yes No
Easy to code Yes No
If back is greater than or equal to front, we use a single for loop at lines
74–75 to loop from front to back as we build our String representation of
the queue. If back is less than front, however, we need to use two for loops:
one to loop from front to the last array index, QUEUE_SIZE – 1 (lines
79–80), and one to loop from 0 to back (lines 81–82).
As before, a very similar program to Example 14.9 can be coded to test all
possible scenarios on the methods ...