Stack:
- Stack is a linear data structure.
- Stack is an ordered list of similar data type.
- Stack in which elements follow a specific order and operations will be performed.
Note: We create Stack using arrays, only the way of representation and Rules of accessing elements vary.
- Stack follows LIFO(Last In First Out).
- Elements will be added from the end called TOP of stack and removes from the same end.
| Array | Stack |
| Linear data structure | Linear data structure |
| Process elements using Index | Process element using top |
| Insert element any where | Insert at top only |
| Delete element from any where | Delete from top |
| Display element in any format | Display elements in LIFO |
Work flow:
Stack ADT: Abstract Data Type specifies the operations can be performed on Stack
- Push: Push an element on to the Stack. Returns “Overflow” if stack is full.
- Pop: Deletes top item from Stack. Returns “Underflow” if Stack is empty.
- Peek: Returns top element of stack but not removes.
- isEmpty: Returns true if stack is empty, else false
- isFull: Returns true if stack is full, else false
- Traverse: Display elements of Stack.