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
FRONT
REAR
Example deque loaded.
—
Size0
Capacity8
Front—
Rear—
Deque, queue, and stack
| Behavior | Operations | Result |
|---|---|---|
| Queue (FIFO) | Add Last + Remove First | Oldest item leaves first. |
| Stack (LIFO) | Add Last + Remove Last | Newest item leaves first. |
| Deque | Add/Remove at both ends | Supports 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.