Ejemplo n.º 1
0
        /// <summary>
        /// AVL rotate double-right operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> DoubleRight(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, "tree");
            Debug.Assert(!tree.IsEmpty);

            if (tree._left.IsEmpty)
            {
                return(tree);
            }

            SortedInt32KeyNode <TValue> rotatedLeftChild = tree.Mutate(left: RotateLeft(tree._left));

            return(RotateRight(rotatedLeftChild));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// AVL rotate right operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> RotateRight(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, nameof(tree));
            Debug.Assert(!tree.IsEmpty);

            if (tree._left.IsEmpty)
            {
                return(tree);
            }

            var left = tree._left;

            return(left.Mutate(right: tree.Mutate(left: left._right)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// AVL rotate left operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> RotateLeft(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, "tree");
            Debug.Assert(!tree.IsEmpty);

            if (tree._right.IsEmpty)
            {
                return(tree);
            }

            var right = tree._right;

            return(right.Mutate(left: tree.Mutate(right: right._left)));
        }