Esempio n. 1
0
            internal Node <AvlNodeInfo> AvlInsert(T value)
            {
                HDebug.Assert(root == null || root.IsRoot());
                AvlNodeInfo avlvalue = new AvlNodeInfo
                {
                    value        = value,
                    left_height  = -1, // height of null node is -1
                    right_height = -1, // height of null node is -1
                };

                if (root == null)
                {
                    Node <AvlNodeInfo> node = BstInsert <AvlNodeInfo>(null, ref root, avlvalue, avlcomp);
                    HDebug.Assert(root == node);
                    HDebug.Assert(root.left == null);
                    HDebug.Assert(root.right == null);
                    HDebug.Assert(root.value.height == 0);
                    return(node);
                }
                else
                {
                    Node <AvlNodeInfo> node = BstInsert <AvlNodeInfo>(null, ref root, avlvalue, avlcomp);
                    HDebug.Assert(node.value.height == 0);
                    UpdateBalance(node, ref root);
                    return(node);
                }
            }
Esempio n. 2
0
 int avlcomp(AvlNodeInfo x, AvlNodeInfo y)
 {
     return(_comp(x.value, y.value));
 }