How to use the Stack and Queue Visualizer
- 1. Pick a structureStack, queue, circular queue or deque, and a capacity.
- 2. Enter a valueThen push, pop, enqueue, dequeue or peek.
- 3. WatchThe picture and the last 12 operations update each time.
The four structures
- Stack: last in, first out. Push adds to the top and pop removes from the top. Used for undo, the call stack, bracket matching and DFS.
- Queue: first in, first out. Enqueue adds at the rear and dequeue removes from the front. Used for task queues, printers and BFS.
- Circular queue: a queue in a fixed array where the rear wraps around, using (rear + 1) mod capacity, so freed slots at the front are reused.
- Deque: a double-ended queue; add or remove at both ends.
Every operation is O(1). With a fixed capacity, adding to a full structure is an overflow, and removing from an empty one is an underflow; the tool shows both, as exam questions often ask about them.
Worked example
Stack with capacity 5: push 10, push 20, push 30, then pop. Pop returns 30, the last one pushed, and 20 becomes the top.
Circular queue with capacity 5: enqueue 10, 20, 30, 40 and 50 (rear moves 0 → 4), then dequeue twice (removing 10 and 20; front moves to 2). Enqueue 60: the rear wraps from 4 to index 0, reusing the slot 10 left. A simple array queue would report it as full even though slots 0 and 1 are empty, which is exactly the problem circular queues solve.
The front (F) and rear (R) markers under the cells, and the count, make it easy to follow pointer questions from your textbook step by step.
Frequently asked questions
Is Python's list a good queue?
As a stack, yes. As a queue, pop(0) is O(n); use collections.deque, which is O(1) at both ends.
How do you tell if a circular queue is full?
Keep a count, or leave one slot empty and check (rear + 1) mod capacity == front.
Can a stack be built from queues?
Yes, with two queues, a classic interview question; one operation becomes O(n).
Is the stack and queue visualizer free to use?
Yes, the stack and queue visualizer is free and costs nothing. Your first operation shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.