Beispiel #1
0
        public void MergeTwoBinaryTrees_FromLeetCode_ShouldMerge()
        {
            var tree1 = new TreeNode(1);

            tree1.left      = new TreeNode(3);
            tree1.right     = new TreeNode(2);
            tree1.left.left = new TreeNode(5);
            var tree2 = new TreeNode(2);

            tree2.left        = new TreeNode(1);
            tree2.left.right  = new TreeNode(4);
            tree2.right       = new TreeNode(3);
            tree2.right.right = new TreeNode(7);

            var result = MergeTwoBinaryTreesImplementation.MergeTrees(tree1, tree2);

            var expectedResult = new TreeNode(3);

            expectedResult.left        = new TreeNode(4);
            expectedResult.right       = new TreeNode(5);
            expectedResult.left.left   = new TreeNode(5);
            expectedResult.left.right  = new TreeNode(4);
            expectedResult.right.right = new TreeNode(7);

            Assert.True(expectedResult.Equals(result) && result.Equals(expectedResult));
        }
Beispiel #2
0
        public void MergeTwoBinaryTrees_EmptyTrees_ShouldReturnEmptyTree()
        {
            TreeNode tree1 = null;
            TreeNode tree2 = null;

            var result = MergeTwoBinaryTreesImplementation.MergeTrees(tree1, tree2);

            Assert.Null(result);
        }