Untitled

 avatar
unknown
plain_text
3 years ago
729 B
2
Indexable
private void rotateLeft(ref Node<T> tree)
        {
            if (tree.Right.BalanceFactor > 0)  //double rotate
                rotateRight(ref tree.Right);
            Node<T> oldRoot = tree;
            Node<T> newRoot = tree;

            newRoot.Left = oldRoot;
            oldRoot.Right = newRoot;
            newRoot.Left = oldRoot.Right;
        }

        private void rotateRight(ref Node<T> tree)
        {
            if (tree.Left.BalanceFactor < 0)
                rotateLeft(ref tree.Left);
            Node<T> oldRoot = tree;
            Node<T> newRoot = tree;

            newRoot.Right = oldRoot;
            oldRoot.Left = newRoot;
            newRoot.Right = oldRoot.Left;

        }