Example #1
0
 public bool InsertData(T x)
 {
     if (x.CompareTo(Data) == 0)
     {
         return(false);
     }
     if (x.CompareTo(Data) < 0)
     {
         if (PLeft == null)
         {
             PLeft = new MyTNode <T>(x);
         }
         else
         {
             return(PLeft.InsertData(x));
         }
     }
     else
     {
         if (pRight == null)
         {
             pRight = new MyTNode <T>(x);
         }
         else
         {
             return(pRight.InsertData(x));
         }
     }
     return(true);
 }
Example #2
0
 public MyTNode <T> LeftMost()
 {
     if (PLeft == null)
     {
         return(this);
     }
     return(PLeft.LeftMost());
 }
Example #3
0
 /// <summary>
 /// Các cách duyệt cây
 /// </summary>
 public void NLR()
 {
     Console.Write(Data + "; ");
     if (PLeft != null)
     {
         PLeft.NLR();
     }
     if (pRight != null)
     {
         pRight.NLR();
     }
 }
Example #4
0
 public MyTNode <T> SearchX(T x)
 {
     if (Data.CompareTo(x) == 0)
     {
         return(this);
     }
     if (Data.CompareTo(x) < 0)
     {
         if (PLeft == null)
         {
             return(null);
         }
         return(PLeft.SearchX(x));
     }
     else
     {
         if (pRight == null)
         {
             return(null);
         }
         return(pRight.SearchX(x));
     }
 }