예제 #1
0
 public MyBinaryNode <K> search(MyBinaryNode <K> current, K key)
 {
     if (current.key.CompareTo(key) > 0 || current.key.CompareTo(key) < 0)
     {
         int compareResult = key.CompareTo(current.key);
         if (compareResult < 0)
         {
             current.left = search(current.left, key);
         }
         else
         {
             current.right = search(current.right, key);
         }
     }
     Console.WriteLine(" Key is searched:" + key);
     return(current);
 }
예제 #2
0
        public MyBinaryNode <K> addRecursively(MyBinaryNode <K> current, K key)
        {
            if (current == null)
            {
                return(new MyBinaryNode <K>(key));
            }
            int compareResult = key.CompareTo(current.key);

            if (compareResult == 0)
            {
                return(current);
            }
            if (compareResult < 0)
            {
                current.left = addRecursively(current.left, key);
            }
            else
            {
                current.right = addRecursively(current.right, key);
            }
            return(current);
        }
 public MyBinaryNode(K key)
 {
     this.key   = key;
     this.left  = null;
     this.right = null;
 }
예제 #4
0
 public int getSizeRecursive(MyBinaryNode <K> current)
 {
     return(current == null ? 0 : 1 + this.getSizeRecursive(current.left)
            + this.getSizeRecursive(current.right));
 }
예제 #5
0
 public void add(K key)
 {
     this.root = this.addRecursively(root, key);
 }