Overflow handling
Warm-up · Multiple choice · about 2 min
An array stack has 3 slots and already holds 4, 7 and 2, so top = 2. A caller runs push(8). What should a well-written push do?
Example 1
Input:
push(8)
Output:
overflow
Learn the idea first: Stacks: push, pop, peek; array and linked implementations, a visual lesson.
More Stacks: push, pop, peek; array and linked implementations problems
- State after a sequence Warm-up
- Implement a stack on an array Standard
- Baseball game score Standard
- Spot the bug: pop returns the wrong value Standard
- Implement a stack with a linked list Challenge