Let a 5 b 7 c 4 d 2 e 3 f 1 g 6 Evaluate the followin
Let a = 5, b = 7, c = 4, d = 2, e = 3, f = 1, g = 6. Evaluate the following RPN expressions without converting
to infix, then convert the expressions to infix and solve to double-check your answers: ( Please show work so that I will learn it)
A. abc*+de--
B. abc/*de*f*g/-
Solution
a) Evaluation of RPN expression
| Input | Action | Stack | Notes |
| a | Operand | 5 | Push onto stack |
| b | Operand | 7 5 | Push onto stack |
| c | Operand | 4 7 5 | Push onto stack |
| * | Operator | 28 5 | Pop the operand 4 and 7 calculate 4*7 and push to stack i.e 28 |
| + | Operator | 33 | Pop the operand 28 and 5 and calculate 28 +5 and push to stack |
| d | Operand | 2 33 | Push onto stack |
| e | Operand | 3 2 33 | Push onto stack |
| - | Operator | 1 33 | Pop 3 and 2 subtract 3-2 and push |
| - | Operator | -32 | Pop 1 and 33 and do 1-33 and push onto stack |
