push and pop operation on stack with flowchart and algorithm
Answers
Answered by
3
Answer:
Algorithm for push in stack:
PUSH(STACK, MAXSTK, TOP, ITEM)
Step 1: whether stack is already full?
if TOP = MAXSTK-1
Print "Stack Overflow"
and return
Step 2: Increase Top by 1
Set : TOP = TOP+1
Step 3: Insert Item in new TOP position
Set : STACK [TOP] = ITEM
Step 4 : Return
Algorithm for pop in stack:
POP(STACK, TOP, ITEM)
Step 1: Whether STACK is already empty?
If TOP = -1
Print" Stack Underflow"
and return
Step 2: Assign TOP element to ITEM
Set: ITEM = STACK[TOP]
Print: ITEM
Step 3: Decrease TOP by 1
Set : TOP = TOP -1
Step 4 : Return
Attachments:
Similar questions