A stack is a last-in, first-out (LIFO) collection. Push adds an element onto the top, pop removes the top element, and peek reads it without removing. All operations run in O(1) and touch only the top — you cannot reach into the middle. Pushing onto a full stack is overflow; popping an empty stack is underflow.
Stack: push, pop, peek and error conditionsPush → top := top + 1; arr[top] := value
Pop → value := arr[top]; top := top - 1
Peek → arr[top]
All operations are O(1).