Пример #1
0
        public BSTNode delete(int value)
        {
            if (value < number)
            {
                if (left != null)
                {
                    left = left.delete(value);
                }
                return(this);
            }
            if (value > number)
            {
                if (right != null)
                {
                    right = right.delete(value);
                }
                return(this);
            }
            if (left == null && right == null)
            {
                return(null);
            }
            if (left == null)
            {
                return(right);
            }
            if (right == null)
            {
                return(left);
            }

            this.number = left.max();
            left.delete(this.number);
            return(this);
        }
Пример #2
0
 /**
  * Delete a number from the tree (if it exists)
  */
 public void delete(int number)
 {
     if (root == null)
     {
         return;
     }
     root = root.delete(number);
 }