Jump to content

4.1.1.3 Stacks (LIFO)

From Computer Science Knowledge Base
Revision as of 14:30, 9 July 2025 by Mr. Goldstein (talk | contribs) (Created page with "=== 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."''' (L...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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