← All chapters
Chapter 05Weeks 7–8Phase 2 ~3.6 h
Stacks & Queues
LIFO and FIFO with arrays and linked lists, the circular queue, and the STL containers.
- 5.1Stacks with an ArrayLast in, first out. The stack ADT (push, pop, peek, isEmpty, isFull) built on a fixed array with a top index, plus overflow and underflow. 45 mineasy
- 5.2Stacks with a Linked ListThe same stack ADT, but the top is the head of a linked list. No fixed capacity, push and pop stay O(1), and the bracket-matching application. 35 mineasy
- 5.3Queues with an ArrayFirst in, first out. Why a naive array queue makes dequeue O(n), how a front index makes it O(1), and the wasted-slot problem that leads to the circular queue. 40 mineasy
- 5.4Queues with a Linked ListKeep two pointers, front and rear. Enqueue at the rear and dequeue at the front, both O(1), with no capacity limit. 30 mineasy
- 5.5Circular QueueLet front and rear wrap around with the modulo operator, so freed slots are reused. All operations O(1) on a fixed array. 40 minmedium
- 5.6std::stack, std::queue & std::dequeThe standard library versions you will use in real code and on LeetCode, their method names, and the classic traps (pop returns void, empty checks). 25 mineasy