- Stack is a linear data structure that follows LIFO (Last In First Out) approach for accessing elements.
- Push, pop, and top (or peek) are the basic operations of a stack.
Following are some of the applications of a stack:
- Check for balanced parentheses in an expression
- Evaluation of a postfix expression
- Problem of Infix to postfix conversion
- Reverse a string
A stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last Out).
A stack is an ordered list of a similar data type.
Real –life example of a stack: Consider an example of plates stacked over one another in the canteen.
The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow LIFO(Last In First Out)/FILO(First In Last Out) order.
The three operations that can be performed on stacks
- inserting an item into a stack (push)
- deleting an item from the stack (pop)
- displaying the contents of the stack(pip)