Prashnikaप्रश्निका
Code
About

Stack and queue simulator

Pick a stack, queue, circular queue or dequeue, give the size of its array and the operations to run, and see the array, the top (or front and rear) and what happened after every step - overflow and underflow included. The table ISC Computer Science data-structure questions ask you to draw.

How to use it

  1. 1Choose what to run: a stack, a queue, a circular queue or a dequeue, and the size of its array.
  2. 2Type the operations in order, e.g. push 10, push 20, pop, or tap an example.
  3. 3Press Run it and read the array, the pointers and what happened after every step.
What to run

Separate with commas. Stack: push 10, pop, peek. Queue and circular queue: insert 10 (or enqueue 10), delete (or dequeue), peek. Dequeue: addfront 10, addrear 10, removefront, removerear.

Step by step

Operation01234topWhat happens
start·····-1an empty stack of 5 cells
push 55····05 is pushed: top becomes 0
pop·····-15 is popped: top becomes -1
pop·····-1UNDERFLOW: the stack is empty, so there is nothing to pop

The numbers above the cells are their positions, counted from 0. A red row is an operation that could not be done.

At the end

empty

The rules followed

  • top starts at -1 (empty). Push: if top is the last cell it is OVERFLOW, otherwise top goes up by 1 and the value is stored there.
  • Pop: if top is -1 it is UNDERFLOW, otherwise the value at top is removed and top goes down by 1.
Start again

About the Stack and queue simulator

What it does

Runs push, pop, insert and delete on an array-based stack, linear queue, circular queue or dequeue, one operation at a time, and shows the array, the pointers (top, or front and rear) and the result after each one. Overflow and underflow are reported instead of changing anything. It is the table that ISC Computer Science data-structure questions ask you to draw.

The conventions it follows

  • Stack: top starts at -1. Push is OVERFLOW when top is the last cell, otherwise top goes up by 1. Pop is UNDERFLOW when top is -1.
  • Queue: front and rear start at -1. A linear queue never reuses the cells before front, so it can be full while cells at the start are free. When the last value leaves, front and rear go back to -1.
  • Circular queue: rear and front wrap from the last cell to cell 0, so every cell can be used; it is full only when every cell is filled.
  • Dequeue: a circular array that you can add to and remove from at both ends: addfront, addrear, removefront, removerear.

How to write the operations

Separate them with commas. Stack: push 10, pop, peek. Queue and circular queue: insert 10 (or enqueue 10), delete (or dequeue), peek. Dequeue: addfront 10, addrear 10, removefront, removerear.

Common questions

What is the difference between overflow and underflow?

Overflow is trying to add to a structure that is full; underflow is trying to remove from one that is empty. In both cases nothing changes.

Why does my linear queue say it is full when there is space at the front?

In a linear queue rear only moves forward, so once rear reaches the last cell no more values can be inserted, even after deletions have freed the cells before front. A circular queue fixes this by wrapping rear round to cell 0 (try the circular queue example).

How is a circular queue different from a dequeue?

A circular queue adds only at the rear and removes only at the front. A dequeue (double-ended queue) can add and remove at both ends.

Practise on real ISC questions

More Computer Science tools

All study tools →