The Queue
This chapter covers the Queue ADT, a collection where items leave in the same order they arrived. We implement it twice, as LinkedQueue and as ArrayQueue built on a circular array, and compare the two.
After reading this chapter, you should be able to:
- Describe the Queue ADT: the
enqueue,dequeue,front, andisEmptyoperations, the first-in, first-out rule, and the documented exception behavior - Implement and trace
LinkedQueue, with the front at the head and the back at the tail, andArrayQueue, with a circular array and asizefield to tell empty from full - Explain how a circular array removes the shifting that a straightforward array queue needs on either
enqueueordequeue - Compare the two implementations in time and memory
You can download the accompanying code for this chapter: starter and solution.
Sections
- Sharing a Printer
- The Queue ADT
- Queue ADT Specification
- Using a Linked List to Implement a Queue
- The LinkedQueue Class
- Implementing front, dequeue, and enqueue
- Tracing the LinkedQueue
- Using an Array to Implement a Queue
- The Circular Array
- Designing the ArrayQueue
- The ArrayQueue Class
- Implementing enqueue
- Tracing the ArrayQueue
- Two Queues, Side by Side