1

I have a BST that uses Generics loaded in from a local file containing all the counties, their state and the population of those counties. my compareTo() is running off of the Population values. How can I create a method calling a min/max that removes all Nodes within that specified range?

I currently have coded it as such:

public void removeRange(int min, int max) {
    removeRange(root, min, max);
}

private void removeRange(TreeNode<T> current, int min, int max) {
    if (current.value.compareTo(min) < 0 || current.value.compareTo(max) > 0) {
        if (current.left != null) {
            removeRange(current.left, min, max);
        }
        if (current.right != null) {
            removeRange(current.right, min, max);
        }
    } 

    else {
        if (current.left != null) {
            removeRange(current.left, min, max);
        }
        if (current.right != null) {
            removeRange(current.right, min, max);
        }
        remove(current.value);
    }
}

I can't use compareTo()'s on Integers as to my current knowledge and I can't find a way to insert my range within my demo class as a Generic type to create my range.

0 Answers0