Programmer's Wiki

A queue is a first-in-first-out list data structure. That is, the first item inserted in the list would be the first item to be retrieved in the list. The "inverse" of a queue is a stack.

This structure inherits both its name and its logic from a waiting line of people, as at a bank or restaurant. Such lines are based on the principle of "first come, first served"; queues are "first in, first out," or FIFO.

Common operations are:

  • enqueue - adds an item in the queue.
  • dequeue - "gets" the next item in the queue, that is, it retrieves the next item in the queue and removes it.

Less common operations are:

  • count - number of items. Rather easy to add in an implementation.
  • peek - retrieves the next item in the queue without removing it.

Common implementations[]

  • using of a single linked list or a double linked list
  • using of two or three Stacks

See also[]

External links[]