Stack or Queue? A Simple Way to Choose

A stack and a queue both hold items, but they express different kinds of work.

Choose a stack when the newest unfinished item should be handled first. Think undo history, nested brackets, backtracking, or depth-first traversal.

Choose a queue when items should be handled in arrival order. Think task processing, customer lines, event streams, or breadth-first traversal.

The deciding question is simple: should the next item be the most recent one or the oldest waiting one?

Find more data-structure guidance in How to Choose the Right Data Structure.


Adapted from Algorithms Made Simple, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top