Codele / Data structures
Stacks
Think of a pile of plates: you add a plate on top, and you take a plate from the top. A stack works the same way, and it powers the Undo button.
- A stack is a pile: you only touch the top.
- Push puts a thing on top. Pop takes the top thing off.
- The newest thing comes off first: last in, first out.
- Undo buttons use a stack: every action is pushed, and Undo pops the newest one.
- Check the stack is not empty before you pop. Popping nothing is a classic bug.
Loading the playable lesson…