Esempio n. 1
0
        static BinaryTree FindSuccessor(BinaryTree tree, BinaryTree node, ref TreeInfo treeInfo)
        {
            if (tree == null || (treeInfo.isFound && treeInfo.Successor != null))
            {
                return(tree);
            }


            FindSuccessor(tree.left, node, ref treeInfo);

            if (treeInfo.isFound)
            {
                if (treeInfo.Successor == null)
                {
                    treeInfo = new TreeInfo(tree);
                }

                return(tree);
            }
            else
            {
                if (tree.value == node.value)
                {
                    treeInfo.isFound = true;
                }
            }

            FindSuccessor(tree.right, node, ref treeInfo);

            return(tree);
        }
Esempio n. 2
0
        static BinaryTree FindSuccessor(BinaryTree tree, BinaryTree node)
        {
            TreeInfo info = new TreeInfo(null);

            FindSuccessor(tree, node, ref info);
            return(info.Successor);
        }