Queue Simulator
A queue is a First-In, First-Out (FIFO) data structure. New elements enter at the rear, while existing elements leave from the front. The element that has waited the longest is therefore removed first.
EnqueueO(1)
DequeueO(1)
Front / RearO(1)
SearchO(n)
Queue operations
FRONT — elements leave here REAR — elements enter here
Enter a value and choose an operation.
Current operationIdle
Items checked0
Queue size0 / 8
Complexity—
Operation history
Core operations
enqueue(x): rear = rear + 1 queue[rear] = x dequeue(): x = queue[front] front = front + 1 return x
Queue concepts
FIFO discipline
The first element inserted is the first one removed. Insertion and removal happen at opposite ends.
Front and rear
The front identifies the next element to leave, while the rear identifies the most recently inserted element.
Searching
A search may inspect every queue element from front to rear, giving O(n) worst-case time.
Common uses
Queues are used in scheduling, buffering, breadth-first search, messaging, and request processing.
Typical time complexities
| Operation | Time | Reason |
|---|---|---|
| Enqueue | O(1) | Add one element at the rear. |
| Dequeue | O(1) | Remove one element from the front. |
| Front / Rear | O(1) | Read one endpoint directly. |
| Search | O(n) | Elements may be checked from front to rear. |
| Space | O(n) | One storage position is needed per queued element. |