Exam-style question
Try this first
Convert the RPN expression 7 2 - 3 + into infix form and describe how a stack can be used to evaluate it.
Model answer
What a good answer should say
- (7 - 2) + 3
Explanation
Why this works
The operands 7 and 2 are followed by -, so they form the sub-expression (7 - 2). The next operand is 3 and the final operator is +, giving (7 - 2) + 3.
To evaluate it with a stack, push 7, push 2, apply -, and push the result 5. Push 3, apply +, and push the final result 8.
Common mistake
No common mistake is linked to this question yet.
