next up previous
Next: Queues Up: CSE 2320: Algorithms and Previous: Example

Pseudocode

   Push(S,x)
      if Stack-Full(S)
      then error "overflow"
      else top(S) = top(S) + 1
           S[top(S)] = x


   Pop(S)
      if Stack-Empty(S)
      then error "underflow"
      else top(S) = top(S) - 1
           return S[top(S) + 1]


   Stack-Empty(S)
      if top(S) = 0
      then return True
      else return False


   Stack-Full(S)
      if top(S) = length(S)
      then return True
      else return False



Copyright © 1998 The University of Texas at Arlington