Chapter 8 · Simulation

Deque Simulator

← Chapter 8
FRONT REAR
Ready.

Deque Simulator

A deque (double-ended queue) lets you insert and remove at both the front and the rear. Use one end only and it behaves as a stack; add at one end and remove at the other and it behaves as a queue.

How to use it

  • Add First / Add Last insert the value; Remove First / Remove Last take the element off that end; Peek First / Peek Last read it without removing it.
  • Capacity (1–8) limits the size; inserting into a full deque is an overflow.
  • Search and Traverse scan from front to rear; Example and Random fill the deque with sample values; Clear empties it; Cancel stops the animation.

Costs

OperationTime
Insert / remove / peek at either endO(1)
Search, traversalO(n)

Typical uses: sliding-window maximum, palindrome checking, work-stealing schedulers.