示例#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)));
 }