コード例 #1
0
        public void InitialTreeHasDepthZero()
        {
            var myTree = new DemoTree <int>();

            myTree.Add(1);

            Assert.AreEqual(0, myTree.Depth());
        }
コード例 #2
0
        private DemoTree <int> CreateTreeWithValues(int numberOfValues)
        {
            if (numberOfValues <= 0)
            {
                return(null);
            }

            var tree = new DemoTree <int>(1);

            for (int i = 2; i <= numberOfValues; i++)
            {
                tree.Add(i);
            }
            return(tree);
        }
コード例 #3
0
 public void Add(T value)
 {
     if (LeftChild == null)
     {
         LeftChild = new DemoTree <T>(value);
         return;
     }
     if (RightChild == null)
     {
         RightChild = new DemoTree <T>(value);
         return;
     }
     if (LeftChild.Depth() <= RightChild.Depth())
     {
         LeftChild.Add(value);
         return;
     }
     RightChild.Add(value);
 }