Stack Data Structure: Push-Pop-Peek Operations
- Stack is linear data structure where you can add data elements
that are connected to each
other in the form of a stack
- Stack follows FILO (First In Last Out) structure
- The last element added to the stack will be the first element
to be removed from it
Stack Operations:
Push
push(): adds an element to the stack. This operation will increase the size of stack by one
Pop
pop(): removes an element from the stack. This operation reduces the size of stack by one
Peek
peek(): checks the top element of the stack. This operation will not remove the element from the stack like pop operation
isEmpty
isEmpty(): checks if the stack is empty or not
Applications of stack data structure:
Stack is used for conversion of infix to postfix.
Stack is used for evaluating expressions with operands
and operations.
Stacks are used for backtracking.
Stacks are used in reversing any set of strings or data.
Parenthesis checking