FRONT
dequeue →
20
[0]
35
[1]
70
[2]
REARREAR
← enqueue
Queue initialized with initial elements
Capacity:
3 / 6
Time:
O(1)Shortcuts: E Enqueue • D Dequeue • F Front • C Clear • M Sound • Z Focus
Implementation Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Queue<T> {
private items: T[] = [];
enqueue(element: T): void {
this.items.push(element);
}
dequeue(): T | undefined {
return this.items.shift();
}
front(): T | undefined {
return this.items[0];
}
isEmpty(): boolean {
return this.items.length === 0;
}
size(): number {
return this.items.length;
}
clear(): void {
this.items = [];
}
}Complexity Analysis
Access
O(n)
Search
O(n)
Insertion
O(1)
Deletion
O(1)
Space Complexity
O(n)
Color Legend
Primary Node (Top / Front / Head)
Inspected / Peeked
Element / Node
A Queue is a linear data structure that follows the First In, First Out (FIFO) order. Items are inserted at the rear (enqueue) and removed from the front (dequeue). Queues are widely used in breadth-first search (BFS), job scheduling buffers, printer spoolers, and message queues.