A pile of pancakes, last in first out
Day 38 of 149
π Full deep-dive with code examples
The Pancake Stack
Mom makes pancakes and stacks them:
π₯ β Last one made (on top)
π₯
π₯
π₯ β First one made (on bottom)
Which pancake do you take first? The top one!
Last In, First Out = LIFO
Stack Operations
Two main things you can do:
- Push: Add to top
- Pop: Remove from top
Push "A" β [A]
Push "B" β [A, B]
Push "C" β [A, B, C]
Pop β [A, B] (returns C)
Pop β [A] (returns B)
Real Uses
Undo/Redo: Each action is pushed. Undo pops the last one!
Browser Back Button: Each page is pushed. Back pops!
Function Calls:
main() calls
login() calls
validate()
When validate() finishes, pop back to login()!
In One Sentence
Stacks store data like a pile where you typically add/remove from the top (last in, first out).
π Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)