What is STACK ?
- Stack is a liner data structure.it means elements in this data structure have a unique predecessor and a unique successor.
- Stack follows Last In First Out (LIFO) technique.
- Initial value of Top is -1 which is known as centennial value.
- When new Element is inserted then top is incremented by one and this term is known as PUSH.
- When an element is deleted then top is decremented by one and this term is known as POP.
- When there is no space for inserting new element and we try to insert then what situations comes known as stack overflow i.e no space for insertion.
- When there is no element in stack and we try to delete then what situations comes known as stack underflow i.e no element for deletion.
- When stack is full then top will be at size-1.
- Stack can be represented or implemented in two ways.
- Stack as an array
- Stack as a linked list
Algorithm: PUSH Operation on Stack
Step 1: If Top=Max-1
Print “Overflow : Stack is full” and Exit
End If
Step 2: Top=Top+1
Step 3: Stack[TOP]=Element
Step 4: End
Algorithm: POP Operation on Stack
Step 1: If TOP=-1
Print “Underflow: Stack is empty” and Exit
End if
Step 2: Set Del_element=Stack[Top]
Step 3: Top=Top-1
Step 4: Return Del_Element
Step 5: End