📄 The slide’s wording & key points
Problem: when a user types something and then clicks "Undo", the editor should undo the last action performed.
In a text editor (like Notepad, Word, or VS Code), when a user types something and then clicks "Undo", the editor should undo the last action performed.
Why Stack? Because a stack works on the Last-In, First-Out (LIFO) principle — the last action is always on top.
Because a stack works on the Last-In, First-Out (LIFO) principle.
1Every edit is pushed onto the stack — it records what that step did
2The last action sits on top — that is exactly what LIFO buys you
3Undo = pop the top + reverse it — undoing a delete puts the character back
4Empty stack = nothing left to undo — "Nothing to undo"
What if we used a queue? A queue dequeues from the front, so Undo would first revert the oldest action Type "Hello" instead of the one just performed, Delete 'o' — completely wrong. That is why Undo needs a stack.