Skip to main contentSkip to solution

Arrange the following statements for conversion from infix to postfix expression.

(A) If the symbol is an operand, put it into the output postfix string.

(B) Print the output postfix string.

(C) Scan the infix expression from left to right.

(D) If the symbol is an operator, check its precedence with the operator at top of stack.

(E) If the symbol has low precedence, pop the operator from the stack and append to the output postfix string.

Solution

✅ Correct Option: 1

(C) Scan the infix expression from left to right.

(A) If the symbol is an operand, put it into the output postfix string.

(D) If the symbol is an operator, check its precedence with the operator at the top of the stack.

(E) If the top operator has higher or equal precedence, pop it from the stack and append it to the output postfix string.

(B) Print the output postfix string.


Options 2, 3 and 4: the output can be printed only after the whole expression has been scanned and the stack emptied, so (B) must be last, and scanning (C) must come before any symbol is handled.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question