What is a queue?
Here we consider the simplest form of a queue. A queue is an ordered collection of objects which operates on a FIFO basis. That is, the first item to be added to a queue will be the first item to be removed from the queue. We call the process of adding an item to a queue “enqueueing” and the process of removing an item from the queue as “dequeueing.” Notice that we enqueue from one end (called the “back” of the queue) and we dequeue from the other end of the queue (called the “front” of the queue). It’s not uncommon to refer to enqueueing as pushing, or “push back” and dequeueing as popping, or “pop front.”
If you’ve ever waited in a line, you understand queues. If you’re from outside the USA, it’s likely you call a queue a “queue”!
Here’s a schematic:
Notice that a queue has a direction: from back to front.
An implementation of a queue should support—at minimum—the enqueue and dequeue operations and a boolean operation to determine if the queue is empty (or not). Other common methods include a size method, which reports the number of elements in a queue, and peek operations (both on front and back).
Further reading:
- Essential Algorithms, chapter 5 (stacks and queues)
- http://www.cplusplus.com/reference/queue/queue/
- https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.