Queue Visualizer
Select an action
5
FRONT
10
18
REAR
Logs
No operations yet
Notes
Queue is a FIFO (First-In-First-Out) data structure.
Enqueue adds at the rear, Dequeue removes from the front, Peek inspects the front.
"Random Enqueue/Dequeue" randomly enqueues or dequeues with animation, and simulates overflow/underflow.
Queue Limit: 6 (simulates overflow)
Animations and diagram visually show queue growth/shrink from left (front) to right (rear).
The UI disables controls while animating for safety.
Peek highlights the front for 3 seconds.
Overflow and underflow events are visually shown.
Implementation (TypeScript)
class Queue<T> {
private arr: T[] = [];
enqueue(value: T) { this.arr.push(value); }
dequeue(): T | undefined { return this.arr.shift(); }
peek(): T | undefined { return this.arr[0]; }
clear() { this.arr = []; }
size() { return this.arr.length; }
}About Queues
A queue is a linear data structure that follows the FIFO principle: the first element added is the first one to be removed.
Applications:
- Task scheduling
- Breadth-first search (BFS)
- Printer/job queues
- Buffering
Main queue operations:
- enqueue(value): Add value at the rear.
- dequeue(): Remove and return the value at the front.
- peek(): Return the value at the front without removing it.
- clear(): Remove all elements.
- size(): Return number of elements.
Queue is often implemented using arrays for simplicity and speed.