A stack is a linear data structure that follows the LIFO (Last In, First Out) principle. This means that the last element added is the first one to be removed.
- Adds an element to the top of the stack.
- If the stack is full, it causes stack overflow.
- Removes the top element of the stack.
- If the stack is empty, it causes stack underflow.
- Happens when you try to push an element into a full stack.
- Example: In a fixed-size array implementation, adding beyond its limit.
- Happens when you try to pop an element from an empty stack.
- Example: Trying to remove an element from an empty stack.