How do you, given any string expression, populate a tree?
I have an assignment that I am stuck on.
I need to evaluate the following expression (( 5 * 10 ) /2 - (( 2 + 3) + 6))
using any data structure.
Using a stack, I am able to verify that the string is well formed. But how can I add the various values into a tree and then evaluate them in order.
Please give me any hints you may have on how I can read the string ((( 490 * 9 ) / 2)/5/6 - (( 2/4 + 3) + 6 * 5))
For instance, How do I get the (-
) to be the root of the three when it is the 15th substring in the input expression? How do I make sure that the (/
)6 expression happens after (/
)5 etc.