Skip to content

Queue Visualizer

First in, first out: enqueue at the rear, dequeue from the front, and watch the front and rear indexes move.

Size: 0 Capacity: 8 front: 0 rear: −1

A queue is first in, first out (FIFO): add at the rear, remove from the front, like a line at a shop.

Step 1 of 1

// Simple array queue: front = 0, rear = −1 at the startenqueue(x):  if rear = N − 1: error "queue full"  rear = rear + 1; a[rear] = xdequeue():  if front > rear: error "queue empty"  x = a[front]; front = front + 1; return xpeek(): return a[front]
Queue operations
OperationTime
EnqueueO(1)
DequeueO(1) with a front index (O(n) if you shift)
PeekO(1)
SearchO(n)
Wasted spaceSlots before front are never reused

A queue is a first in, first out (FIFO) collection, like a line at a shop: new items join at the rear and leave from the front. This visualizer stores a queue in an array of 8 slots with a front index and a rear index, and animates every enqueue, dequeue and peek with the matching pseudocode.

Keep enqueueing and dequeueing and you will hit the weakness of this simple array queue: rear reaches the last slot and the queue reports full even though the slots before front are empty. That wasted space is exactly the problem the circular queue solves.

How to use the Queue Visualizer tool

  1. Type a value and press Enqueue to add it at the rear.
  2. Press Dequeue to remove the value at the front, or Peek to look at it.
  3. Watch the front and rear markers under the array move to the right.
  4. Fill the queue up to the end to see the “full at the end” problem, then compare with the circular queue.

Why use ToolOrca Queue Visualizer

  • Array queue with front and rear indexes
  • Enqueue, dequeue and peek animated step by step
  • Shows the wasted space problem of a linear queue
  • Pseudocode highlighted for every step
  • Code in C++, Java, Python and JavaScript
  • Complexity table

How a queue works

A queue has two ends. enqueue(x) adds x at the rear, dequeue() removes and returns the front value, and peek() returns the front value without removing it. The first value in is always the first value out: FIFO.

In a simple array queue, front starts at 0 and rear at −1. Enqueue increments rear and writes the value; dequeue reads a[front] and increments front. Both are O(1). The catch is that front and rear only move right. Once rear reaches the end, no more values fit, even if many slots at the front are free. Shifting everything back to index 0 would fix it but costs O(n) per dequeue.

Where queues are used

Queues model anything that waits its turn: print jobs, keyboard input buffers, web server requests, message queues between services, task schedulers and breadth-first search in graphs. Most languages provide one: std::queue in C++, ArrayDeque in Java, collections.deque in Python.

Every visualizer on this site runs in your browser with the same controls: Play, Pause, Step forward, Step back and a speed slider. You can also drag the position slider to jump to any step, or focus the drawing and use the Space bar and arrow keys.

Frequently asked questions

What does FIFO mean?

First in, first out: items leave the queue in the same order they arrived.

What is the difference between a stack and a queue?

A stack removes the newest item first (LIFO); a queue removes the oldest item first (FIFO).

Why does a simple array queue say it is full when it is not?

Because front and rear only move forward. When rear reaches the last index, the free slots before front cannot be reused. A circular queue wraps rear around to index 0 to fix this.

Why not use list.pop(0) in Python as a queue?

Removing the first element of a Python list shifts every other element, which is O(n). collections.deque removes from the front in O(1).