next up previous
Next: Insertion Up: CSE 2320: Algorithms and Previous: Successor(n)

Successor(n)

   Successor(n)
      if right(n) <> NIL
      then return Min(right(n))
      p = Parent(n)
      while p <> NIL and n = right(p)
         n = p
         p = Parent(p)
      return(p)

Successor is



   Predecessor(n)
      if left(n) <> NIL
      then return Max(left(n))
      p = Parent(n)
      while p <> NIL and n = left(p)
         n = p
         p = Parent(p)
      return(p)

Predecessor is



Copyright © 1998 The University of Texas at Arlington