Skip to main content

Command Palette

Search for a command to run...

πŸ₯ž Stacks Explained Like You're 5

Published
β€’1 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

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.

More from this blog

esreekarreddy

132 posts