public int getMinValue() { if (left == null) { return(this.value); } else { return(left.getMinValue()); } }
public void Remove(int value, BST parent) { if (value < this.value) { if (left != null) { left.Remove(value, this); } } else if (value > this.value) { if (right != null) { right.Remove(value, this); } } else { if (left != null && right != null) { this.value = right.getMinValue(); right.Remove(this.value, this); } else if (parent == null) { if (left != null) { this.value = left.value; right = left.right; left = left.left; } else if (right != null) { this.value = right.value; left = right.left; right = right.right; } else { // this is a single node tree; do nothing } } else if (parent.left == this) { parent.left = left != null ? left : right; } else if (parent.right == this) { parent.right = left != null ? left : right; } } }