ITPEC FE Morning October 2019 Question 5
ITPEC FE Morning October 2019 — Question 5 of 80
Postfix Expression Evaluation — evaluate a reverse Polish notation expression using a stack.
Expression: 5 4 6 + × 4 9 3 ÷ + ×
Step-by-step stack trace:
- •
5→ stack:[5] - •
4→ stack:[5, 4] - •
6→ stack:[5, 4, 6] - •
+→4 + 6 = 10→ stack:[5, 10] - •
×→5 × 10 = 50→ stack:[50] - •
4→ stack:[50, 4] - •
9→ stack:[50, 4, 9] - •
3→ stack:[50, 4, 9, 3] - •
÷→9 ÷ 3 = 3→ stack:[50, 4, 3] - •
+→4 + 3 = 7→ stack:[50, 7] - •
×→50 × 7 = 350→ stack:[350]
Result: 350
Why not others:
- (a) 98 — incorrect arithmetic sequence
- (b) 154 — incorrect arithmetic sequence
- (c) 238 — incorrect arithmetic sequence
Key rule: In postfix evaluation, scan left to right. Push operands onto a stack. When an operator appears, pop two operands (second popped is the left operand), apply the operator, and push the result back.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.