Stack is a linear data structure which can be accessed only from one of its end for storing and retrieving data.
Stack can be implemented by using:
- Arrays(Static, Dynamic).
- Linked List.
Operation of Stack:
TOP -> Where insertion takes place.
PUSH -> PUSH is a term used to insert element into stack.
POP -> POP is a term used to delete element from stack.
MAX -> Returns the maximum no of elements held by stack.
Algorithm for PUSH Operation:
1) Check whether stack is already full or not/Overflow.
TOP=MAX ; Print “Stack is already full”;
3) Insert ITEM at new position of TOP
Set Stack[TOP]= ITEM
Algorithm for POP Operation:
1) Check whether stack is already empty or not/Underflow.
TOP=NULL ; Print “Stack is already empty”;
2) Assign TOP item to ITEM
3) Set TOP=TOP-1;