Can anyone explain how I Solve a expression Tree when I'm given x as a parameter?
For example, I have the equation ((2*x)) + 4and let's say in the parameter, x = 3. This would give us 10 and the method would return this.
The way I thought about doing this was to do it recursively but I can't really do it because the parameter has to be the double x.
Any thoughts?
Here's the code I have so far.
public double evaluate(double x) throws ExpressionTreeNodeException {
ExpressionTreeNode n = new ExpressionTreeNode();
n.setValue(getValue());
n.setType(getType());
if ( n.getRightChild() == null && n.getLeftChild() == null){
double RootLeaf = Double.parseDouble(n.getValue());
return RootLeaf;
} else {
double operand1 =
return ()
}
}