Write a program that takes as input an arithmetic expression and should do the following:
1. Check that the expression is well-formed: that means the number of opening parenthesis ‘(‘ is equal to closing ones, the operands are numeric characters, the operators are +, -, * or /.
2. Build the expression tree based on the arithmetic expression. This will take into consideration the priority of some operators over the others. Each node in the tree has as value a number or a string. In particular, leaf nodes have number values while intermediary nodes have a string value.
3. Evaluate the outcome of the whole expression by traversing the tree (using one variant of depth-first search) starting with leaf nodes and evaluating each branch until you get the result.
2. Build the expression tree based on the arithmetic expression. This will take into consideration the priority of some operators over the others. Each node in the tree has as value a number or a string. In particular, leaf nodes have number values while intermediary nodes have a string value.
The code you found builds an RPN stack.
You need to be building a tree, a snippet of which perhaps looks something like this.
../..
| |
| v
v 2
..+..
| |
v v
9 1
Your main needs to be like this, to match the terms of your assignment.