|
The following examples, presented first in standard infix notation, converted to reverse Polish notation by using the shunting yard algorithm, all use the same four operands but combined with different operators and parentheses. Operators are assumed to be binary.
$(1 + 2) \times (3 + 4)$ in standard infix notation becomes $1 \quad 2 + 3 \quad 4 + \quad \times$ in reverse Polish notation. Both expressions should evaluate to 21, each in the appropriate calculator.
$1 + 2 \times 3 + 4$ standard becomes $1 \quad 2 \quad 3 \times 4 +$ RPN. Both evaluate to 11.
$1 + 2 \times (3 + 4)$ turns to $1 \quad 2 \quad 3 \quad 4 + \quad \times \quad +$ Evaluate to 15.
$(1 + 2) \times 3 + 4$ is $1 \quad 2 + 3 \times 4 +$ Evaluate to 13.
|