Chapter 8 · Simulation

Queue Simulator

← Chapter 8
FRONT REAR
Ready.

Queue Simulator

A queue is a FIFO (first in, first out) structure: elements join at the rear (REAR) and leave from the front (FRONT).

How to use

  • Enqueue adds the value you typed and Random Enqueue adds a random one; Dequeue removes the front element.
  • Peek Front and Peek Rear read the value at either end; Is Empty? checks the size.
  • The capacity is 8: enqueueing into a full queue is an overflow, dequeueing from an empty one an underflow.
  • Search scans from front to rear; Fill Example loads sample values, Clear empties the queue, and Cancel stops the animation.

Costs

OperationTime
Enqueue, dequeue, front, rear, isEmptyO(1)
SearchO(n)

Typical uses: printer and CPU scheduling, buffers, breadth-first search.