CMPS 144L Lab Activity
Wraparound Array-based
representation of queues

             

Name_____________________

The following shows one possible wraparound array-based representation of a queue, such as is the basis for the QueueViaArray Java class that was discussed in lecture. (There is a link to it on the course web page.)

           0   1   2   3   4   5   6   7   8   9   
         +---+---+---+---+---+---+---+---+---+---+
contents |BUG|RAT| - | - | - | - | - |DOG|CAT|ELK|
         +---+---+---+---+---+---+---+---+---+---+

         +---+               +---+  
frontLoc | 7 |      numItems | 5 |
         +---+               +---+

Note: A dash (−) means that the contents of the array location is irrelevant.

(a) List the animals on the queue, from front to rear (i.e., in the order in which they entered the queue).

(b) Suppose that EMU is enqueued. Show how the underlying representation of the queue (i.e., the array contents[] and the values of the variables frontLoc and numItems) will change as a result.

(c) Now suppose that the dequeue operation is applied four times in succession. Once again show the updated state of the underlying representation (i.e., the array contents[], etc.)