Data Structure (2130702)

BE | Semester-3   Winter-2016 | 01/02/2017

Q2) (a)

Write a pseudo-code for PUSH and POP operations of stack.

For PUSH Operations:-
1.[Check for stack overflow]
 If TOP ≥ N
 Then write (‘STACK OVERFLOW’)
  Return
2. [Increment TOP]
 TOP ←TOP + 1
3. [Insert Element]
 S[TOP] ←X
4. [Finished]
 Return

For POP Operations:-
1. [Check for underflow of stack]
 If TOP = 0
 Then Write (‘STACK UNDERFLOW ON POP’)
  Take action in response to underflow
  Return
2. [Decrement Pointer]
 TOP ← TOP – 1
3. [Return former top element of stack]
 Return (S[TOP + 1])