Computer Science
Confusing a Stack and a Queue
Students remove items from a stack in the same order they were added, as if it were a queue.
Quick check
Why students make it
Both structures store items in a line, so it is easy to focus on insertion order and ignore the removal rule. The words push, pop, enqueue, and dequeue also get mixed up when students memorize names instead of behavior.
The rule done right
A stack is LIFO, so the last item added is the first item removed. A queue is FIFO, so the first item added is the first item removed.
Related resources
- Data Structures Overview Cheat Sheet
- Tree Traversal Reference Cheat Sheet
- Graph Algorithms (BFS, DFS, Dijkstra) Cheat Sheet
- Heap & Priority Queue Reference Cheat Sheet
- Data Structures, Stacks, Queues, and Trees Worksheet
- CS, Arrays and Lists Worksheet
- CS, Graph Algorithms, BFS and DFS Worksheet
- Data Structure Visualizer Tool
- Recursion & Call Stack Visualizer Tool
- Pathfinding Algorithm Visualizer Tool
- Data Structures & Tree Traversal Lab Lab
- Recursion & Data Structures Lab Lab
- Graph Theory & Networks Lab Lab