Exam-style question
Try this first
Convert the infix expression (A + B) * (C - D) into RPN. Explain how the order of the RPN expression represents the brackets.
Model answer
What a good answer should say
- AB+CD-*
Explanation
Why this works
The first bracketed sub-expression, A + B, becomes AB+. The second bracketed sub-expression, C - D, becomes CD-.
The multiplication operator is placed after both completed sub-expressions, producing AB+CD-*. The position of the operators preserves the order imposed by the brackets, so additional brackets are not required in the RPN form.
Common mistake
No common mistake is linked to this question yet.
