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.