[prev] 53 [next]

Tree Rotation (cont)

Algorithm for right rotation:

rotateRight(n1):
|  Input  tree n1
|  Output n1 rotated to the right
|
|  if n1 is empty or left(n1) is empty then
|     return n1
|  end if
|  n2=left(n1)
|  left(n1)=right(n2)
|  right(n2)=n1
|  return n2

[Diagram:Pic/left-right-rotation.png]