Back

How Queues Work

A queue is a collection of items in a First In First Out (FIFO) structure. They operate just like real life queues: when a data item arrives, it is added to the back of the queue. When removing data items, the first to go is the one at the front of the queue – similar to a person at the front of a shopping queue being served first. These operations are referred to as ‘enqueue’ (adding items) and ‘dequeue’ (removing items).

A pointer called ‘head’ points to the first element in a queue. Another pointer called ‘tail’ points to the location or index that a new item should be enqueued at. This is the position after the last element in the queue.