EvaluateReversePolishNotation
代码说明:
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [ 2 , 1 , + , 3 , * ] -> ((2 + 1) * 3) -> 9 [ 4 , 13 , 5 , / , + ] -> (4 + (13 / 5)) -> 6 分析:这一题就是写程序计算逆波兰式的结果,遍历表达式,碰到操作数入栈,碰到操作符就从栈顶取出两个操作数,再将计算后的结果入栈,最后栈中剩余的唯一操作数就是计算结果。(. Evaluate the value of an arithmetic expression in Reverse Polish Notation Valid operators are+,-,*,/Each operand may be an integer or another expression Some examples:.. [" 2" , " 1" , " +" , " 3 " ," * " ]-> ((2+ 1)* 3)-> 9 [" 4 " ," 13 " ," 5 " ," /" ," + " ]-> (4+ (13/After this problem is to write a program to calculate the inverse Polish results, iterate expression operand stack encounter, encounter operator to fetch two operands the stack, and then calculated as follows:> 6 Analysis- 5)) The results of the stack, the only remaining operand stack is the final calculations.)
下载说明:请别用迅雷下载,失败请重下,重下不扣分!