Programmer's Wiki

A deque (double-ended queue) is a generic data stucture which can be modified from either end, in contrast to both queues and stacks. A deque implementation may be extended to act as either of these other data structures by restricting certain operations. For example, a deque becomes a stack if it refuses to modify its beginning (shift and unshift).

Common operations are:

  • unshift - adds an item to the beginning.
  • shift - removes an item from the beginning.
  • push - adds an item to the end.
  • pop - removes an item from the end.

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.