예제 #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
        //[Test]
        public void TestCase1()
        {
            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
            };

            Program1.BranchSums(tree);
            //Utils.AssertTrue(Program1.BranchSums(tree).SequenceEqual(expected));
        }