Example #1
0
        public void ExchangeHeadAndTail()
        {
            var root = new TreeNode(10)
            {
                left = new TreeNode(5)
                {
                    left  = new TreeNode(25),
                    right = new TreeNode(7)
                },
                right = new TreeNode(20)
                {
                    left  = new TreeNode(16),
                    right = new TreeNode(1)
                }
            };

            var algo = new RecoverBinarySearchTree_99();

            algo.RecoverTree(root);

            Assert.Equal(1, root.left.left.val);
            Assert.Equal(25, root.right.right.val);
        }
Example #2
0
        public void ExchangeNeighbour()
        {
            var root = new TreeNode(7)
            {
                left = new TreeNode(5)
                {
                    left  = new TreeNode(1),
                    right = new TreeNode(10)
                },
                right = new TreeNode(20)
                {
                    left  = new TreeNode(16),
                    right = new TreeNode(25)
                }
            };

            var algo = new RecoverBinarySearchTree_99();

            algo.RecoverTree(root);

            Assert.Equal(10, root.val);
            Assert.Equal(7, root.left.right.val);
        }