A Stack is a linear data structure in which all element insertions and deletions are restricted to a single end, universally referred to as the TOP of the stack. It operates strictly under the LIFO (Last-In, First-Out) or FILO (First-In, Last-Out) access discipline.
Core Primitive Operations:
- `push(item)`: Inserts a new element at the TOP of the stack. Increments stack size.
- `pop()`: Removes and returns the element currently residing at the TOP of the stack. Decrements stack size. If the stack is empty, triggers Stack Underflow.
- `peek()` / `top()`: Returns the value of the top element *without* removing it. Triggers Underflow if the stack is empty.
- `isEmpty()`: Boolean predicate returning `True` if the stack contains zero elements, `False` otherwise.
Stack Boundary Conditions:
- Stack Underflow: An error condition that occurs when an algorithm attempts to execute a `pop()` or `peek()` operation on a stack that contains no elements (`isEmpty() == True`).
- Stack Overflow: An error condition that occurs in a bounded, fixed-capacity stack when a `push()` is attempted on an already full stack. (Note: Dynamic Python lists grow automatically, so overflow occurs only when physical system memory is exhausted or recursive recursion limits are exceeded).