Stack-based Evaluation of Prefix Expressions
Write a program that reads prefix expressions and prints their values. Each input expression should be entered on its own line, and the program should terminate when the user enters a blank line. Assume that there are only binary operators and that the expressions contain no variables. Your program should use a stack. Here are sample input–output pairs:
Hint : Go through the prefix expression from left to right, pushing operators and values onto a stack. Whenever you have two values on the stack with an operator just underneath them, pop the two values, pop the operator, apply the operator to the value, and push the result (which is a value) onto the stack. The tricky part is how to store both operators of type char and values of type int on the same stack. Think about a type such as the following:
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.