A Stack is a Last-In-First-Out (LIFO) data structure — like a stack of plates! 🍽️
💡 Think of it like this: Imagine stacking plates. You always put new plates on TOP and take from the TOP. The last plate you put on is the first one you take off. That's LIFO!
Stack operations (all O(1)):
stack.append(x) — Push: add element to the topstack.pop() — Pop: remove and return top elementstack[-1] — Peek: look at top without removinglen(stack) == 0 — isEmpty: check if stack is emptyWhere stacks appear everywhere:
stack.pop()
20
stack.pop()
15
stack[-1]
10