예제 #1
0
 public static void InOrderPrint(BinarySeachTree <T> parentNode)
 {
     if (parentNode == null)
     {
         return;
     }
     InOrderPrint(parentNode.Left);
     Console.WriteLine(parentNode.Value);
     InOrderPrint(parentNode.Right);
 }
예제 #2
0
        public static BinarySeachTree <T> Insert(BinarySeachTree <T> parentNode, BinarySeachTree <T> newNode)
        {
            if (parentNode == null)
            {
                return(newNode);
            }

            if (Compare(newNode.Value, parentNode.Value) >= 0)
            {
                parentNode.Right = Insert(parentNode.Right, newNode);
            }
            else
            {
                parentNode.Left = Insert(parentNode.Left, newNode);
            }
            return(parentNode);
        }
예제 #3
0
 public static BinarySeachTree <T> Search(BinarySeachTree <T> parentNode, BinarySeachTree <T> searchOperand)
 {
     if (parentNode == null)
     {
         return(null);
     }
     if (parentNode == searchOperand)
     {
         return(parentNode);
     }
     if (searchOperand >= parentNode)
     {
         return(Search(parentNode.Right, searchOperand));
     }
     else
     {
         return(Search(parentNode.Left, searchOperand));
     }
 }
예제 #4
0
 public static BinarySeachTree <T> Search(BinarySeachTree <T> parentNode, T searchOperand)
 {
     return(Search(parentNode, new BinarySeachTree <T>(searchOperand)));
 }
예제 #5
0
 public static BinarySeachTree <T> Insert(BinarySeachTree <T> parentNode, T value)
 {
     return(Insert(parentNode, new BinarySeachTree <T>(value)));
 }