4.1.1.3 Stacks (LIFO)
Appearance
4.1.1.3 Stacks: Last In, First Out (LIFO)
Imagine a stack of plates. When you put a new plate on, it goes on top. When you take a plate off, you always take the one from the very top. A stack in computer science works exactly like this!
It follows a rule called LIFO, which stands for Last In, First Out. The last item you put in the stack is always the first item you can take out.
- Putting items on a stack is called "pushing." (Like pushing a plate onto the stack)
- Taking items off a stack is called "popping." (Like popping a plate off the top)
- Examples of Stacks in real life:
- The "Undo" button in a program: The last thing you did is the first thing you can undo.
- The "Back" button in a web browser: The last page you visited is the first one you go back to.
Bibliography for Stacks
- Kiddle: Data structure Facts for Kids (Stack)
- Shopify Blog: What Is Last In First Out (LIFO)? Definition and Guide