コード例 #1
0
 public void Add(IComparable obj)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     int num2 = -1;
     BSTreeNode node = new BSTreeNode(obj);
     BSTreeNode root = base.Root as BSTreeNode;
     BSTreeNode node3 = null;
     while (root != null)
     {
         int num = obj.CompareTo(root.Value);
         if (num == 0)
         {
             return;
         }
         if (num > 0)
         {
             node3 = root;
             root = root.LeftChild;
             num2 = 0;
         }
         else if (num < 0)
         {
             node3 = root;
             root = root.RightChild;
             num2 = 1;
         }
         if (node3 == null)
         {
             base.proot = node;
         }
         else
         {
             node3[num2] = node;
         }
     }
 }
コード例 #2
0
 protected virtual BSTreeNode Search(BSTreeNode current, IComparable obj)
 {
     if (current == null)
     {
         return null;
     }
     int num = ((IComparable) current.Value).CompareTo(obj);
     if (num == 0)
     {
         return current;
     }
     if (num > 0)
     {
         return this.Search(current.LeftChild, obj);
     }
     return this.Search(current.RightChild, obj);
 }