示例#1
0
 void Add(V value, MyBinaryNode <V> node)
 {
     if (head == null)
     {
         head = new MyBinaryNode <V>(value);
     }
     else if (node.value.CompareTo(value) > 0)
     {
         if (node.left == null)
         {
             node.left = new MyBinaryNode <V>(value);
         }
         else
         {
             Add(value, node.left);
         }
     }
     else if (node.value.CompareTo(value) < 0)
     {
         if (node.right == null)
         {
             node.right = new MyBinaryNode <V>(value);
         }
         else
         {
             Add(value, node.right);
         }
     }
 }
示例#2
0
        void Traverse(MyBinaryNode <V> node)
        {
            if (node.left != null)
            {
                Traverse(node.left);
            }

            Console.WriteLine(node.value);

            if (node.right != null)
            {
                Traverse(node.right);
            }
        }
示例#3
0
 void Find(V value, MyBinaryNode <V> node)
 {
     if (value.Equals(node.value))
     {
         Console.WriteLine("Element found");
         return;
     }
     else if (value.CompareTo(node.value) < 0 && node.left != null)
     {
         Find(value, node.left);
     }
     else if (value.CompareTo(node.value) > 0 && node.right != null)
     {
         Find(value, node.right);
     }
     else
     {
         Console.WriteLine("Element Not Found");
     }
 }
示例#4
0
 public BST()
 {
     head = null;
 }