Exemplo n.º 1
0
        private static void Rotate(ref AvlNode <T> oldRoot, int left, int right)
        {
            var newRoot = oldRoot.Children[left];

            oldRoot.Children[left]  = newRoot.Children[right];
            newRoot.Children[right] = oldRoot;

            oldRoot.UpdateSizes();
            newRoot.UpdateSizes();

            oldRoot = newRoot;
        }
Exemplo n.º 2
0
        private static void BalanceIfRightIsHeavy(ref AvlNode <T> node)
        {
            node.UpdateSizes();

            if (node.Balance < -1)
            {
                if (node.Right.Balance > 0)
                {
                    var child = node.Right;
                    RotateRight(ref child);
                    node.Right = child;
                }
                RotateLeft(ref node);
            }
        }