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
- 1Choose what to run: a stack, a queue, a circular queue or a dequeue, and the size of its array.
- 2Type the operations in order, e.g. push 10, push 20, pop, or tap an example.
- 3Press Run it and read the array, the pointers and what happened after every step.
Step by step
| Operation | 0 | 1 | 2 | 3 | 4 | front | rear | What happens |
|---|---|---|---|---|---|---|---|---|
| start | · | · | · | · | · | -1 | -1 | an empty queue of 5 cells |
| insert 1 | 1 | · | · | · | · | 0 | 0 | 1 is inserted at the rear: rear becomes 0 |
| insert 2 | 1 | 2 | · | · | · | 0 | 1 | 2 is inserted at the rear: rear becomes 1 |
| insert 3 | 1 | 2 | 3 | · | · | 0 | 2 | 3 is inserted at the rear: rear becomes 2 |
| insert 4 | 1 | 2 | 3 | 4 | · | 0 | 3 | 4 is inserted at the rear: rear becomes 3 |
| delete | · | 2 | 3 | 4 | · | 1 | 3 | 1 is deleted from the front: front becomes 1 |
| delete | · | · | 3 | 4 | · | 2 | 3 | 2 is deleted from the front: front becomes 2 |
| insert 5 | · | · | 3 | 4 | 5 | 2 | 4 | 5 is inserted at the rear: rear becomes 4 |
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
3 elements, front to rear: 3, 4, 5
The rules followed
- front and rear start at -1. Insert: if rear is the last cell it is OVERFLOW (cells before front are not reused); otherwise rear goes up by 1 (the first insert sets front and rear to 0).
- Delete: if front is -1 it is UNDERFLOW; otherwise the value at front is removed and front goes up by 1. When the last value leaves, front and rear go back to -1.
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
- Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First…2020 Specimen
- A Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out)…2022 Specimen
- Recursive data structure follows the LIFO principle.2024
- ___________ is called a Self-Referential Data structure.2025 Practice
- The Central Processing Unit (CPU) scheduling follows the principle of _________ data structure.2025 Practice
- Queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from…2017
- A circular queue is a linear data structure that allows data insertion at the rear and removal from the…2025
- How is a linear queue structure different from a circular queue structure?2020
- State the principle by which the stack data structure works.2022 Specimen
- A circular queue is a linear data structure that allows data insertion at the rear and removal from the…2025 Improvement
More Computer Science tools
- Boolean algebra solverSimplify any expression: the laws step by step, truth table, K-map and the logic circuit.
- Infix to postfix converterInfix to postfix or prefix with the stack table, and postfix evaluation step by step.
- Binary tree and BST toolBuild a binary search tree, rebuild a tree from two traversals, and get every traversal and fact.
- Recursion visualiserWatch factorial, Fibonacci, power, GCD and sum of digits run: the calls, the call stack and the returns.
- Tower of Hanoi visualiserWatch the discs move between the pegs while the recursive calls and the call stack build up.
- Binary search tree visualiserWatch values being inserted into a binary search tree, searched for, and walked inorder, preorder and postorder.
- Binary tree traversal visualiserClick a binary tree together and watch preorder, inorder and postorder walk it, with the recursive calls on the call stack.
- Stack and queue visualiserWatch push, pop, insert and delete move top, front and rear along the array, with overflow and underflow.
- Linked list visualiserWatch nodes being added, deleted, searched, traversed and reversed, with start, p, prev and curr moving along the arrows.
- 2D array visualiserWatch row-wise, column-wise, diagonal, boundary and spiral walks number the cells of a 2D array in the order they print.
- Sorting visualiserWatch bubble, selection and insertion sort compare, swap and shift your own list, step by step.
- Linear and binary search visualiserWatch a linear or binary search look for a value in your list, and count the comparisons.