← Back

Queue Simulator

What is a Queue?

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 removed first.

EnqueueO(1)
DequeueO(1)
Front / RearO(1)
SearchO(n)

Queue operations

350 ms
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

  1. No operations yet.

Queue pseudocode

enqueue(value):
    if queue is full:
        report overflow
    else:
        add value at rear
        rear = rear + 1

Queue concepts

FIFO behavior

The first element enqueued is the first element dequeued. New values never skip ahead of values already waiting in the queue.

Front and rear

The front identifies the next removable element. The rear identifies where the next new element will be inserted.

Overflow and underflow

Overflow occurs when Enqueue is attempted on a full fixed-capacity queue. Underflow occurs when Dequeue or Front is attempted on an empty queue.

Common applications

Queues are used in task scheduling, print processing, message buffering, breadth-first search, request handling, and event systems.

Typical time complexities

Operation Time Reason
Enqueue O(1) The new value is added directly at the rear.
Dequeue O(1) The front reference advances to the next element.
Front / Rear O(1) The boundary values are read directly.
Search O(n) Every queued value may need to be inspected.
Space O(n) Storage grows with the number of queued values.