예제 #1
0
 /// <summary>
 /// Determines the depth of the next vacant position in the tree
 /// </summary>
 /// <returns></returns>
 public int Depth()
 {
     if (LeftChild == null || RightChild == null)
     {
         return(0);
     }
     return(1 + Math.Max(LeftChild.Depth(), RightChild.Depth()));
 }
예제 #2
0
 public void Add(T value)
 {
     if (LeftChild == null)
     {
         LeftChild = new DemoTree1 <T>(value);
     }
     else if (RightChild == null)
     {
         RightChild = new DemoTree1 <T>(value);
     }
     else if (LeftChild.Depth() < RightChild.Depth())
     {
         LeftChild.Add(value);
     }
     else
     {
         RightChild.Add(value);
     }
 }
예제 #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);
 }
예제 #4
0
        public TreeNode <T> Add(T value)
        {
            if (LeftChild == null)
            {
                LeftChild = new TreeNode <T>(value);
                return(LeftChild);
            }
            else if (RightChild == null)
            {
                RightChild = new TreeNode <T>(value);
                return(RightChild);
            }

            var ld = LeftChild.Depth();
            var rd = RightChild.Depth();

            if (LeftChild.Depth() <= RightChild.Depth())
            {
                return(LeftChild.Add(value));
            }

            return(RightChild.Add(value));
        }