0
点赞
收藏
分享

微信扫一扫

C++ Reverse Polish Notation

Yaphets_巍 2022-03-12 阅读 132

Reverse Polish Notation
Reverse Polish Notation (RPN), also known as polish postfix notation or
simply postfix notation, is a mathematical notation in which operators
follow their operands.
For example, the infix expression P1: 5 + ((1 + 2) * 4) - 3 can be written
like this in Reverse Polish Notation: P2: 5 1 2 + 4 * + 3 -
In terms of the operation, the expression P1 and P2 can be evaluated as
P1 P2
5 + ((1 + 2) * 4) - 3
5 + (3 * 4) - 3
5 + 12 - 3
17 - 3
14
5 1 2 + 4 * + 3 -
5 3 4 * + 3 -
5 12 + 3 -
17 3 -
14
The reverse polish notation has many advantages, such as there is no
bracket in the expression and no priority is needed for the operators,
most importantly, the evaluation process is quite simple. The reverse
polish notation could be evaluated by using a stack.
Evaluation Algorithm
Input Operat

举报

相关推荐

0 条评论