Пример #1
0
        public TestBinaryTree Insert(List <int> values, int i)
        {
            if (i >= values.Count)
            {
                return(null);
            }

            List <TestBinaryTree> queue = new List <TestBinaryTree>();

            queue.Add(this);
            while (queue.Count > 0)
            {
                TestBinaryTree current = queue[0];
                queue.RemoveAt(0);
                if (current.left == null)
                {
                    current.left = new TestBinaryTree(values[i]);
                    break;
                }
                queue.Add((TestBinaryTree)current.left);
                if (current.right == null)
                {
                    current.right = new TestBinaryTree(values[i]);
                    break;
                }
                queue.Add((TestBinaryTree)current.right);
            }
            Insert(values, i + 1);
            return(this);
        }
Пример #2
0
        public void TestCase1()
        {
            TestBinaryTree tree     = new TestBinaryTree(1);
            List <int>     expected = new List <int>()
            {
                1
            };

            Assert.IsTrue(Program.BranchSums(tree).SequenceEqual(expected));
        }
Пример #3
0
        public void TestCase5()
        {
            TestBinaryTree tree = new TestBinaryTree(1).Insert(new List <int>()
            {
                2, 3, 4, 5, 6, 7, 8, 9, 10
            });
            List <int> expected = new List <int>()
            {
                15, 16, 18, 10, 11
            };

            Assert.IsTrue(Program.BranchSums(tree).SequenceEqual(expected));
        }
Пример #4
0
        public void TestCase4()
        {
            TestBinaryTree tree = new TestBinaryTree(1).Insert(new List <int>()
            {
                2, 3, 4, 5
            });
            List <int> expected = new List <int>()
            {
                7, 8, 4
            };

            Assert.IsTrue(Program.BranchSums(tree).SequenceEqual(expected));
        }
Пример #5
0
        public void TestCase9()
        {
            TestBinaryTree tree = new TestBinaryTree(0);

            tree.left              = new TestBinaryTree(9);
            tree.right             = new TestBinaryTree(1);
            tree.right.left        = new TestBinaryTree(15);
            tree.right.right       = new TestBinaryTree(10);
            tree.right.right.left  = new TestBinaryTree(100);
            tree.right.right.right = new TestBinaryTree(200);
            List <int> expected = new List <int>()
            {
                9, 16, 111, 211
            };

            Assert.IsTrue(Program.BranchSums(tree).SequenceEqual(expected));
        }