What is a queue?

Published

2023-08-05

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:

A schematic of a queue, showing enqueue and dequeue operations.

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:

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.