Queue and Deque
First-in, first-out processing and its two-ended extension
A queue preserves arrival order
A queue inserts at the rear and removes from the front. The oldest waiting item leaves first, which makes queues natural for scheduling, buffering, and breadth-first search. With a linked list or circular array, enqueue and dequeue both take O(1) time.
Press enqueue to add an item at the rear.
A circular array reuses slots vacated at the front instead of shifting every remaining value. Head and tail indices wrap around the capacity while the logical order stays unchanged.
A deque opens both ends
A double-ended queue supports insertion and removal at both the front and rear. It can behave like either a queue or a stack, and it powers sliding-window algorithms that must discard old candidates from one side while adding new candidates on the other.
A deque accepts insertions and removals at both ends. Try all four operations.
Queues traverse a tree level by level, while stacks traverse depth first.