What’s a Queue?
What’s a Stack?
Now think about stacking blocks. You put one block on top of another. The last block you add is the first one that will fall if you knock it over, that’s how a stack works too! In a stack, things are added and removed from the top, like when you take off your socks, then your shoes, then your pants.
In both cases, we're organizing things in order, but in different ways. A queue is like a line, and a stack is like a tower!
Examples
- A stack is like plates in a kitchen, you place new plates on top, and take them off from the top too.
- In a video game, enemies might be queued up for a boss fight, while your inventory uses a stack.
Ask a question
See also
- What are computational limits?
- What are computational methods?
- How algorithms shape what you see on social media?
- How Do Computers Understand Language?
- How do algorithms help people make decisions every day?