CS With NehalCS With Nehal

Queue (ADT) Simulator

Show enqueue, dequeue, front, rear, overflow, and underflow.

Queue Properties
Size: 3Capacity: ∞Front: 0Rear: 2

Algorithm

Current line is highlighted.

Initial queue loaded.
A

index 0

front
B

index 1

C

index 2

rear
empty

index 3

empty

index 4

empty

index 5

Animation Speed — 900ms

About This Simulation

This queue simulator shows a FIFO queue with enqueue, dequeue, peek and reset, with the front and rear positions marked and a timeline you can play back.

Features

  • Enqueue, dequeue, peek and reset operations
  • Front and rear positions shown
  • Empty slots shown as placeholders
  • Overflow and underflow messages
  • Timeline playback of every operation

Explanation

A queue is a linear data structure that follows FIFO: the first element added is the first one removed. Elements are added at the rear and removed from the front, like people waiting in a line.

How it works

  1. Enqueue: if the queue is full, report overflow. Otherwise place the value at the rear and move rear forward.
  2. Dequeue: if the queue is empty, report underflow. Otherwise remove the value at the front and move front forward.
  3. Peek: return the value at the front without removing it.
  4. In a simple array queue, front and rear only move forward, so space freed at the start cannot be reused. A circular queue fixes this.

Why it matters

Queues are used in CPU and printer scheduling, buffering data streams, handling requests in servers and breadth first search. It is a core CSE220 data structure.

Frequently Asked Questions

What is the time complexity of queue operations?

Enqueue, dequeue and peek all take O(1) time in an array or linked-list implementation.

What is the difference between a queue and a stack?

A queue is FIFO (first in, first out) and a stack is LIFO (last in, first out). A queue adds at the rear and removes from the front; a stack adds and removes at the top.

Why is a circular queue better than a linear queue?

In a linear array queue, the slots before the front are wasted after dequeues, so the queue can report full while space remains. A circular queue wraps the rear around to the start with modulo arithmetic and reuses that space.

What are the types of queues?

Common types are the simple (linear) queue, circular queue, priority queue and double-ended queue (deque).

Topics covered

  • Queue ADT
  • FIFO (First In, First Out)
  • Enqueue and Dequeue
  • Front and Rear
  • Array Implementation of a Queue

Tags

  • queue
  • enqueue
  • dequeue
  • fifo
  • front
  • rear

Related Simulations