Queue
A Queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. Elements are added at the rear and removed from the front. Common operations include enqueue and dequeue.
Queue Visualization
Speed1x
Queue Engine
FIFO Visualization Chamber
Size
0/8
Front
—
Rear
—
State
Idle
Front / Dequeue
Rear / Enqueue
#0
#1
#2
#3
#4
#5
#6
#7
Queue: Empty
Action: System idle.
Synced Logic
Operation Flow
Live
1 function queueOperations() {
2 enqueue(value) -> insert at rear
3 queue.push(value)
4
5 dequeue() -> remove from front
6 queue.shift()
7
8 reset() -> queue = []
9 }
Legend
Front → first element removed
Rear → new element inserted
Middle elements waiting in order
Concept
A Queue follows FIFO — First In, First Out.
Dequeue removes from the front, while enqueue inserts at the rear.
Dequeue removes from the front, while enqueue inserts at the rear.
Complexity
Time Complexity:
O(1) for enqueue/dequeueSpace Complexity:
O(n)Pseudocode
class Queue:
function enqueue(item):
queue.append(item)
function dequeue():
if queue is empty:
return error
return queue.remove_first()
function front():
return queue[0]Related Algorithms
Stack
A Stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Elements are added and removed from the same end (top). Common operations include push, pop, and peek.
Time: O(1) for push/pop/peek | Space: O(n)
Linked List
A Linked List is a linear data structure where elements are stored in nodes, and each node points to the next node. It allows dynamic memory allocation and efficient insertion/deletion operations.
Time: O(1) for insert/delete, O(n) for search | Space: O(n)