public void RotateRight(OrderedTreeNode x)
{
// pushing node x down and to the Right to balance the tree. x's Left child (y)
// replaces x (since x < y), and y's Right child becomes x's Left child
// (since it's < x but > y).
OrderedTreeNode y = x.Left; // get x's Left node, this becomes y
// set x's Right link
x.Left = y.Right; // y's Right child becomes x's Left child
// modify parents
if(y.Right != sentinelNode)
y.Right.Parent = x; // sets y's Right Parent to x
if(y != sentinelNode)
y.Parent = x.Parent; // set y's Parent to x's Parent
if(x.Parent != null) { // null=rbTree, could also have used rbTree
// determine which side of it's Parent x was on
if(x == x.Parent.Right)
x.Parent.Right = y; // set Right Parent to y
else
x.Parent.Left = y; // set Left Parent to y
}
else
rbTree = y; // at rbTree, set it to y
// link x and y
y.Right = x; // put x on y's Right
if(x != sentinelNode) // set y as x's Parent
x.Parent = y;
}