one way to eveluate a prefix expression is to use queue. to eveluate the expression scan it repeatedly untill you know the final expression value, read it repeatedly untill you know the final expression value. in each scan replace an operator followed by two operands by the calculated value.
for example,the following expression that is evaluated to 159:
- + * 9 + 2 8 * + 4 8 6 3
we can scan the expression and store it in a queue. during the scan, when the operator is followed by two operands, such as + 2 8,we put the result, 10 in the queue
after the first scan, we have
- + * 9 10 * 12 6 3
after the second scan we have
- + 90 72 3
after the third scan, we have
- 162
after the fourth scan, we have
159
hope you all can help=)