Preview
IB DP Computer Science — B2 Programming — Data structures | SL | B2.2.3
📋 What You Will Learn
- Explain LIFO and why a stack gives access to one end only — the top
- Define and use the fundamental operations: push , pop , peek , isEmpty
- Trace a sequence of stack operations, showing the stack's state after every step
- Explain how stack operations affect performance and memory usage
- Choose (and justify) a stack for problems such as undo, back-navigation and matching brackets
🍽️ Why This Matters A canteen's spring-loaded pile of plates: you can only put a plate on the top, and only take the top plate off. The last plate added is the first one removed. That single restriction — one end only — is the whole idea of a stack, and it is precisely what makes "undo" and the browser back button work.
What a Stack Is
📖 Definition — Stack A stack is a last in, first out (LIFO) data structure: elements are added and removed at one end only , called the top . The most recently pushed element