In process of converting the infix expression A + B * C - D to postfix expression, what will be the correct order of stack operations?
(A). Push *
(B). Push +
(C). Pop * and + then Push -
(D). Pop -
In process of converting the infix expression A + B * C - D to postfix expression, what will be the correct order of stack operations?
(A). Push *
(B). Push +
(C). Pop * and + then Push -
(D). Pop -
Solution
Scan the expression from left to right. Operands go straight to the output, and an operator pops any stack operators of equal or higher precedence before it is pushed.
(B) Push +: the stack is empty, so + is pushed after A is output.
(A) Push *: * has higher precedence than +, so it is pushed on top without popping.
(C) Pop * and + then Push -: - has lower precedence than *, and equal precedence to + (left-associative), so both are popped before - is pushed.
(D) Pop -: at the end of the input, the remaining operator - is popped.
The resulting postfix expression is
Related questions:
2025: 16 May Shift 1
2025: 22 May Shift 1
2026: 13 May Shift 2