예제 #1
0
 public override BinaryTree <T> Add(T value)
 {
     if (value.CompareTo(Value) == -1)
     {
         if (LeftChild.GetType() == typeof(Branch <T>))
         {
             LeftChild.Add(value);
         }
         else
         {
             Branch <T> tempBranch = new Branch <T>(value);
             LeftChild = tempBranch;
         }
     }
     else if (value.CompareTo(Value) == 1)
     {
         if (RightChild.GetType() == typeof(Branch <T>))
         {
             RightChild.Add(value);
         }
         else
         {
             Branch <T> tempBranch = new Branch <T>(value);
             RightChild = tempBranch;
         }
     }
     return(this);
 }
예제 #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));
        }
예제 #5
0
        public void Add(int payload)
        {
            if (Payload is null)
            {
                Payload = payload;
                return;
            }

            if (payload >= Payload)
            {
                if (RightChild is not null)
                {
                    RightChild.Add(payload);
                    return;
                }
                RightChild = new BinaryTree()
                {
                    Payload = payload, Parrent = this
                };
                return;
            }

            if (payload < Payload)
            {
                if (LeftChild is not null)
                {
                    LeftChild.Add(payload);
                    return;
                }
                LeftChild = new BinaryTree()
                {
                    Payload = payload, Parrent = this
                };
                return;
            }
        }