Stacks and queues
Two structures that limit where items go in and come out, and the classic problems they solve: matching brackets, postfix expressions and fair waiting lines.
About 7 hours of study
Learning objectives
- Build a stack and a queue on an array and on a list
- Check brackets and evaluate postfix with a stack
- Use the remainder operator for a circular queue
- Detect overflow and underflow
Lessons
- 1
Stacks
Last in, first out: a stack on an array with push, pop, overflow and underflow.
- 2
Using stacks: brackets and postfix
Check that brackets match, evaluate postfix expressions, and turn infix into postfix.
- 3
Queues
First in, first out: a circular array queue that wraps around, and a linked queue with front and rear.
Module practice
- A stack of numbersEasy
- Undo typingMedium
- A stack that knows its minimumHard
- Depth of bracketsEasy
- Balanced bracketsMedium
- Evaluate a postfix expressionMedium
- Infix to postfixHard
- The ticket lineEasy
- A circular queueMedium
- A queue from two stacksHard