LOGBOOK

HELP

Quiz Entry - updated: 2026.09.29

What is a deque (double-ended queue), and what are its operations?

A deque ("deck") allows inserting and removing at both ends: addFirst, addLast, removeFirst, removeLast, plus first() and last() to look without removing; reading from an empty deque returns null.

Stack, queue and deque compared by which ends they allow

* A stack uses one end, a queue uses each end for one job, a deque uses both ends for everything. *

Operation What it does
addFirst(e) insert at the front
addLast(e) insert at the rear
removeFirst() remove and return the front element
removeLast() remove and return the rear element
first() / last() return the front / rear element without removing it
size(), isEmpty() as for stack and queue

The name is short for Double-Ended QUEue, and it is pronounced like "deck".

A deque is the generalisation of both earlier ADTs. Use only addLast and removeLast and it behaves as a stack. Use only addLast and removeFirst and it behaves as a queue. That is why Java's ArrayDeque and Python's collections.deque are the recommended types for stacks and queues alike.

Go deeper:

  • doc Double-ended queue — operations, implementations and language support.
  • doc java.util.Deque — the interface's table mapping stack and queue methods onto deque methods.

From Quiz: ADS / Linear Data Structures: Lists, Stacks, Queues, Deques, Iterators | Updated: Sep 29, 2026