next up previous
Next: Insertion Up: CSE 2320: Algorithms and Previous: Rotations

Rotations

   Right-Rotate(T,x)
      x = left(y)           ; assume left(y) <> NIL
      left(y) = right(x)
      if right(x) <> NIL
      then parent(right(x)) = x
      parent(x) = parent(y)
      if parent(y) = NIL
      then root(T) = x
      else if x = left(parent(y))
           then left(parent(y)) = x
           else right(parent(y)) = x
      right(x) = y
      parent(y) = x

Insertion Example



Copyright © 1998 The University of Texas at Arlington