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); }
/** * Delete a number from the tree (if it exists) */ public void delete(int number) { if (root == null) { return; } root = root.delete(number); }