public int evaluate() {
   if (root == null) {
        return -100000;
    }

    return evaluateHelper(root); (error)

}

private int evaluateHelper(MyBinaryTreeNode rt) {

    if (rt.left == null) {

        return Integer.parseInt(rt.data.toString()); (error)

    }

    switch (rt.data.toString()) {

        case "+":

            return evaluateHelper(rt.left) + evaluateHelper(rt.right);

        case "-":

            return evaluateHelper(rt.left) - evaluateHelper(rt.right);

        case "/":

            return evaluateHelper(rt.left) / evaluateHelper(rt.right);

        case "*":

            return evaluateHelper(rt.left) * evaluateHelper(rt.right);

        case "%":

            return evaluateHelper(rt.left) % evaluateHelper(rt.right);

        default:

            return -100000;

    }

}

Recommended Answers

Is there a question that needs asking?

Jump to Post

All 2 Replies

It looks like whatever is inrt.data at line 14 is not a valid string representation of an integer.
But since you don't show that data there's nothing more anyone can say.
You could printrt.data just before calling parseInt to see what values you are processing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.