Advertisement

Algorithm for STACK


PUSH Operation
Push(stack, top, maxstk, item)
1.  [stack already filled?] 
If top = maxstk then : print : OVERFLOW and return. 
2.  Set top : = top +1 . [increases top by 1] 
3.   Set stack[top] := item [inserts item in new TOP position] 
4.  Return. 
  POP Operation
Pop(stack, top, item)
 variable item. 
1.  [Stack has an item to be removed?] 
If top := 0, then : print : UNDERFLOW  and return. 
2.  Set item := stack[top]. [assigns top element to item]. 

3.  Set top := top -1.[decreases top by 1].