A queue is an abstract data type following a first-in-first-out (FIFO) flow. The following operations are defined on queues:

  • enqueue(item) - add item to the rear of the queue.
  • dequeue() - remove the oldest item from the front of the queue.

Variations

Priority Queues

Priority queues associate a numeric priority with each element, and uses this in conjunction with insertion order to determine order of retrieval. An additional parameter, priority is taken by the enqueue operation, and this value is associated with the element in the structure. The dequeue operation removes the element with the highest priority (usually implemented as lowest value). If there are multiple elements with this priority then the one inserted earliest is to be returned.

Implementation

Queues can be implemented using various different data structures. The most common implementations use a Linked List or Dynamic Array. Binary Heaps can be used for an efficient implementation of Priority Queues.