Пример #1
0
        protected Node MakeCompleteTree(int[] seq)
        {
            if (seq.Length < 1)
            {
                return(null);
            }

            var root  = new Node(seq[0]);
            var adder = new CompleteTreeChildNodeAdder(root);

            for (var i = 1; i < seq.Length; i++)
            {
                adder.AddChildNode(seq[i]);
            }

            return(root);
        }
Пример #2
0
        public void TestCompleteTreeChildNodeAdder()
        {
            var root  = new Node(1);
            var adder = new CompleteTreeChildNodeAdder(root);

            adder.AddChildNode(2);
            Assert.Test(root.Left.Data == 2);

            adder.AddChildNode(3);
            Assert.Test(root.Right.Data == 3);

            adder.AddChildNode(4);
            Assert.Test(root.Left.Left.Data == 4);

            adder.AddChildNode(5);
            Assert.Test(root.Left.Right.Data == 5);

            adder.AddChildNode(6);
            Assert.Test(root.Right.Left.Data == 6);

            adder.AddChildNode(7);
            Assert.Test(root.Right.Right.Data == 7);
        }
Пример #3
0
        protected Node MakeCompleteTree(int[] seq)
        {
            if (seq.Length < 1)
            {
                return null;
            }

            var root = new Node(seq[0]);
            var adder = new CompleteTreeChildNodeAdder(root);
            for (var i = 1; i < seq.Length; i++)
            {
                adder.AddChildNode(seq[i]);
            }

            return root;
        }
Пример #4
0
        public void TestCompleteTreeChildNodeAdder()
        {
            var root = new Node(1);
            var adder = new CompleteTreeChildNodeAdder(root);

            adder.AddChildNode(2);
            Assert.Test(root.Left.Data == 2);

            adder.AddChildNode(3);
            Assert.Test(root.Right.Data == 3);

            adder.AddChildNode(4);
            Assert.Test(root.Left.Left.Data == 4);

            adder.AddChildNode(5);
            Assert.Test(root.Left.Right.Data == 5);

            adder.AddChildNode(6);
            Assert.Test(root.Right.Left.Data == 6);

            adder.AddChildNode(7);
            Assert.Test(root.Right.Right.Data == 7);
        }