Stack and queue visualiser
Pick a stack, queue, circular queue or dequeue, give the size of its array and the operations to run, then press Play. You see the array, the pointers (top, or front and rear) moving after every operation, the cell that changed, overflow and underflow in red, and the Java line that did it. For the table ISC asks you to draw, use the stack and queue simulator.
How to use it
- 1Choose a stack, queue, circular queue or dequeue and the size of its array, then type the operations, or tap an example.
- 2Press Show me, then Play. After each operation the array and the pointers are redrawn and the Java line that did it is lit.
- 3Watch top, or front and rear, move; overflow and underflow turn the sentence red and change nothing.
The animation needs JavaScript. Every step is written out below.
Result
- Result
- from the top: 60 50 40 20 10
Every step in words (9 steps)
- An empty stack with 5 cells: top = -1.
- push 10: 10 is pushed: top becomes 0.
- push 20: 20 is pushed: top becomes 1.
- push 30: 30 is pushed: top becomes 2.
- pop: 30 is popped: top becomes 1.
- peek: the top element is 20.
- push 40: 40 is pushed: top becomes 2.
- push 50: 50 is pushed: top becomes 3.
- push 60: 60 is pushed: top becomes 4.
About the Stack and queue visualiser
What it does
Runs push, pop, insert and delete on an array-based stack, linear queue, circular queue or dequeue and plays them back one operation at a time: the cell that was just filled or emptied is marked, top (or front and rear) is shown under the cell it points at, and a sentence says what happened. The Java method that did it is shown with the running line lit. It follows exactly the same rules as the stack and queue simulator, which gives the table that ISC questions ask you to draw.
The conventions it follows
- Stack: top starts at -1; push is OVERFLOW when top is the last cell, 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 round from the last cell to cell 0, so it is full only when every cell is filled.
- Dequeue: a circular array with addFront, addRear, removeFront and removeRear.
The limits
An array of 1 to 12 cells and up to 40 operations. Separate the operations with commas, e.g. push 10, push 20, pop.
Common questions
What is overflow and underflow?
Overflow is trying to add to a structure that is full, underflow is trying to remove from one that is empty. Nothing changes in either case, and the visualiser shows the sentence in red.
Why does my linear queue say it is full when there are free cells at the front?
In a linear queue rear only moves forward, so once rear reaches the last cell nothing more can be inserted, even after deletions have freed the cells before front. Use a circular queue, where rear wraps round to cell 0 (tap the circular queue example).
How does a circular queue wrap round?
When rear (or front) is at the last cell, the next position is cell 0, calculated as (rear + 1) % size. Watch rear jump from the last cell back to 0 in the circular queue example.
Can I see the code in Python, JavaScript or C++?
Yes. Choose the language in the menu above the code. Only the listing changes: the steps are always worked out from the Java program that ISC uses, and the highlighted line moves to the matching line of the language you chose.
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.
- Stack and queue simulatorRun push, pop, insert and delete on a stack, queue, circular queue or dequeue, and watch the pointers move.
- 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.
- 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.