Beispiel #1
0
        public void Run()
        {
            TreeNode root = new TreeNode(1);

            root.Left        = new TreeNode(2);
            root.Right       = new TreeNode(3);
            root.Left.Left   = new TreeNode(4);
            root.Left.Right  = new TreeNode(5);
            root.Right.Right = new TreeNode(6);
            BTreePrinter.Inorder(root);
            var result = GenerateMirrorTree(root);

            BTreePrinter.Inorder(result);
        }
Beispiel #2
0
        public void Run()
        {
            /*
             *        50                            50
             *     /     \         delete(20)      /   \
             *    30      70       --------->    30     70
             *   /  \    /  \                     \    /  \
             * 20   40  60   80                   40  60   80
             */

            TreeNode root = new TreeNode(50);

            root.Left        = new TreeNode(30);
            root.Right       = new TreeNode(70);
            root.Left.Left   = new TreeNode(20);
            root.Left.Right  = new TreeNode(40);
            root.Right.Left  = new TreeNode(60);
            root.Right.Right = new TreeNode(80);
            DeleteNode(root, 20);
            BTreePrinter.Inorder(root);
        }
        public void Run()
        {
            /* Let us construct below tree
             *  1
             * / \
             * 2   3
             * / \   \
             * 4   5   6    */
            var root = new TreeNode(1);

            root.Left        = new TreeNode(2);
            root.Right       = new TreeNode(3);
            root.Left.Left   = new TreeNode(4);
            root.Left.Right  = new TreeNode(5);
            root.Right.Right = new TreeNode(6);

            UpdateTree(root);

            Console.WriteLine("Inorder traversal of the modified tree is \n");
            BTreePrinter.Inorder(root);
        }