next up previous
Next: RB-Delete-Fixup(T,x) Up: CSE 2320: Algorithms and Previous: Deletion

Sortof BST Delete

1.
Use of sentinel nil(T) for NIL leaves
2.
Call to RB-Delete-Fixup

   RB-Delete(R,z)                ; return deleted node
      if left(z) = nil(T) or right(z) = nil(T)
      then d = z
      else d = Successor(z)
      if left(d) <> nil(T)
      then c = left(d)
      else c = right(d)
      parent(c) = parent(d)      ; no test for NIL with sentinel
      if parent(d) = nil(T)
      then root(T) = c
      else if d = left(parent(d))
           then left(parent(d))) = c
           else right(parent(d))) = c
      if d <> z
      then key(z) = key(d)
      if color(d) = Black
      then RB-Delete-Fixup(T,c)  ; c is now "Double-Black"
      return d



Copyright © 1998 The University of Texas at Arlington