System.util.collections.OrderedTree.RotateLeft C# (CSharp) Method

RotateLeft() public method

RotateLeft Rebalance the tree by rotating the nodes to the left
public RotateLeft ( OrderedTreeNode x ) : void
x OrderedTreeNode
return void
        public void RotateLeft(OrderedTreeNode x)
        {
            // pushing node x down and to the Left to balance the tree. x's Right child (y)
            // replaces x (since y > x), and y's Left child becomes x's Right child
            // (since it's < y but > x).

            OrderedTreeNode y = x.Right; // get x's Right node, this becomes y

            // set x's Right link
            x.Right = y.Left; // y's Left child's becomes x's Right child

            // modify parents
            if(y.Left != sentinelNode)
                y.Left.Parent = x; // sets y's Left Parent to x

            if(y != sentinelNode)
                y.Parent = x.Parent; // set y's Parent to x's Parent

            if(x.Parent != null) {
                // determine which side of it's Parent x was on
                if(x == x.Parent.Left)
                    x.Parent.Left = y; // set Left Parent to y
                else
                    x.Parent.Right = y; // set Right Parent to y
            }
            else
                rbTree = y; // at rbTree, set it to y

            // link x and y
            y.Left = x; // put x on y's Left
            if(x != sentinelNode) // set y as x's Parent
                x.Parent = y;
        }