STACK
A stack is a fundamental data structure used in computer science. It follows the LIFO (Last In, First Out)
principle, meaning that the last element added to the stack is the first one to be removed. Think of a stack
of plates: you add new plates to the top, and when you remove a plate, you take the one from the top of the
stack first..
Key Characteristics of a Stack:
- Last In, First Out (LIFO): The last element pushed onto the stack is the first one to be popped out.
- Push: The operation to add an element to the stack.
- Pop: The operation to remove the top element from the stack.
- Operators: Symbols used to perform operations, such as addition (+), comparison (==), or logical evaluation (&&).
- Peek/Top: The operation to look at the top element of the stack without removing it..
- IsEmpty: Checks if the stack is empty
- Size: Returns the number of elements in the stack.