Deque Simulator

A deque (double-ended queue) supports insertion and removal at both the front and the rear. This makes it more flexible than a standard queue and allows the same structure to behave like either a queue or a stack.

Add FirstO(1)
Add LastO(1)
Remove FirstO(1)
Remove LastO(1)

Deque operations

350 ms
FRONT
REAR

Example deque loaded.

Size0
Capacity8
Front
Rear

Deque, queue, and stack

BehaviorOperationsResult
Queue (FIFO)Add Last + Remove FirstOldest item leaves first.
Stack (LIFO)Add Last + Remove LastNewest item leaves first.
DequeAdd/Remove at both endsSupports both patterns.

Concepts

Double-ended access

The defining property of a deque is efficient insertion and removal at both ends.

Queue behavior

Using addLast and removeFirst gives standard FIFO behavior.

Stack behavior

Using addLast and removeLast gives LIFO behavior without changing the underlying structure.

Applications

Deques are useful in sliding-window algorithms, task scheduling, palindrome checks, work-stealing systems, and monotonic-queue techniques.