Beispiel #1
0
 static SuccessorTreeNode GetMin(SuccessorTreeNode node)
 {
     while (node.left != null)
     {
         node = node.left;
     }
     return(node);
 }
Beispiel #2
0
        static SuccessorTreeNode FindSuccessorFromParent(SuccessorTreeNode node)
        {
            if (node.right != null)
            {
                return(GetMin(node.right));
            }

            SuccessorTreeNode parent = node.parent;

            while (parent != null && parent.right == node)
            {
                node   = parent;
                parent = parent.parent;
            }
            return(parent);
        }
Beispiel #3
0
        static SuccessorTreeNode FindSuccessforFromRoot(SuccessorTreeNode root, SuccessorTreeNode node)
        {
            if (node.right != null)
            {
                return(GetMin(node.right));
            }

            SuccessorTreeNode successor = null;

            while (root != null)
            {
                if ((int)node.val <= (int)root.val)
                {
                    successor = root;
                    root      = root.left;
                }
                else if ((int)node.val > (int)root.val)
                {
                    root = root.right;
                }
            }
            return(successor);
        }
Beispiel #4
0
 public SuccessorTreeNode(object data)
 {
     val  = data;
     left = right = parent;
 }