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

Pseudocode

   Enqueue(Q,x)
      if Queue-Full(Q)
      then error "overflow"
      else Q[tail(Q)] = x
           if tail(Q) = length(Q)
           then tail(Q) = 1
           else tail(Q) = tail(Q) + 1


   Dequeue(Q)
      if Queue-Empty(Q)
      then error "underflow"
      else x = Q[head(Q)]
           if head(Q) = length(Q)
           then head(Q) = 1
           else head(Q) = head(Q) + 1
      return x


   Queue-Full(Q)
      if tail(Q) = length(Q)
      then n = 1
      else n = tail(Q) + 1
      if n = head(Q)
      then return True
      else return False


   Queue-Empty(Q)
      if head(Q) = tail(Q)
      then return True
      else return False



Copyright © 1998 The University of Texas at Arlington