Stack (data structure) facts for kids
The stack is a very important way to organize information in computer science. Imagine a stack of playing cards placed face down. You can only easily reach the card that is right on top.
When you want to look at the top card, you can do two main things:
- You can peek at it, which means you look at it but leave it on the stack.
- You can pop it off, which means you take it completely off the stack.
If you want to add a new card to the top, you push it onto the stack.
A stack is often called a last-in-first-out (LIFO) collection. This means the last item you added (pushed) is always the first one you can take off (pop). So, if you put an ace on top of your card stack, that ace will be the first card you can remove.
Contents
How Stacks Were Invented
The idea of a stack was first suggested in 1955. It was then officially protected by a patent in 1957 by a German scientist named Friedrich L. Bauer. Around the same time, an Australian scientist named Charles Leonard Hamblin also came up with the same idea on his own.
Other Things You Can Do With Stacks
In modern computer programming, stacks usually have more actions than just "push" and "pop." Here are a few common ones:
- Length: Some stacks have a way to tell you how many items are currently in the stack.
- Top (or Peek): This action lets you see the item at the very top of the stack without removing it.
- Dup: This action makes an exact copy of the item that is currently at the top of the stack.
Related Topics
Images for kids
See also
In Spanish: Pila (informática) para niños