Stack Data Structure

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means that the last element added to the stack will be the first one to be removed. Think of it like a stack of plates where you add and remove plates from the top.

Key Operations

- Push: Adds an element to the top of the stack.
- Pop: Removes the element from the top of the stack.
- Peek: Retrieves the top element of the stack without removing it.
- isEmpty: Checks whether the stack is empty or not.

Time Complexity

- Push: O(1)
- Pop: O(1)
- Peek: O(1)