Study guides & original practice
Stack versus queue practice
A stack removes the most recently added item first. A queue removes the earliest waiting item first. Choose the structure by the required access order.
By ExamCat · Original study lesson · Published September 24, 2026
Understand the method
The common names are LIFO for stacks and FIFO for queues. These describe behavior, not a specific programming-language implementation. Real systems may use priority queues or other policies, which are different from a simple FIFO queue.
Worked example, step by step
Add A, then B, then C to an initially empty stack and an initially empty queue.
- The stack top is C, so its first removal returns C.
- The queue front is A, so its first removal returns A.
- Removing all items gives C, B, A for the stack.
- Removing all items gives A, B, C for the queue. The insertion order was identical; the removal policy changed.
A mistake to watch for
A queue is not necessarily a priority ranking. In a priority queue, urgency or another key can override arrival order. State the policy before predicting which task runs next.
Try it yourself: three questions
Write an answer before opening the explanation. For calculations, keep your units and intermediate steps; for concepts, state the reason for your choice.
1. Push 1, push 2, pop, push 3, pop on a stack. What do the pops return?
Show answer and explanation
First 2, then 3. The value 1 remains after these operations.
2. Enqueue 1, enqueue 2, dequeue, enqueue 3, dequeue. What returns?
Show answer and explanation
First 1, then 2. The value 3 remains in the queue.
3. Why is an undo history often modeled with a stack?
Show answer and explanation
The latest action is usually the first one reversed. More complicated undo/redo behavior may use additional structures.
Build your next practice session
Mark the first step where your reasoning differed from the explanation. Turn that step into a question, answer it without looking, then change one condition in the example and explain what would change. A correct guess is a reason to revisit the method.
Use the free flashcard maker for your own question-and-answer pairs, or bring your course material into PDF-to-flashcards practice.
Further reading
OpenStax: data structures and algorithms provides textbook background. The worked scenario and practice questions on this page were written independently for ExamCat.
Related lessons
Practice your own class material
Generate flashcards, notes and quizzes from your lecture notes in Exam Cat.
Try 7 days free ↗Yearly plan: 7 days free, then $39.99/year. Cancel before the trial ends to avoid a charge.
APUSH study guide · Biology study guide · APUSH practice · All study tools
