A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle, meaning the last element added is the first to be removed.
Key Operations:
- Push: Adds an element to the top of the stack.
- Pop: Removes the top element.
- Peek/Top: Views the top element without removing it.
Example:
Think of a stack of plates; you add and remove plates from the top.
Applications:
- Expression evaluation (e.g., postfix, prefix)
- Undo/Redo functionality in software
- Backtracking algorithms (e.g., maze solving)
- Function call management in recursion