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;
}
}
snowwizard 0 Newbie Poster
rproffitt 2,662 "Nothing to see here." Moderator
snowwizard commented: how do i fix this problem +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.