Skip to main content

Convert A+B-(C*D/E+F)-G*H to postfix

Short answer

Converting A+B-(C*D/E+F)-G*H yields postfix AB+CD*E/F+-GH*-. Stack: operands outputted; operators popped when equal/higher precedence appears.

Show status of stack while converting the following infix expression to postfix expression: A+B-(CD/E+F)-GH.

Infix: A + B - ( C * D / E + F ) - G * H. Equal-precedence operators are popped before pushing the new one (left-to-right).

StepSymbolStack (bottom → top)Postfix output
1A(empty)A
2++A
3B+AB
4--AB+
5(-(AB+
6C-(AB+C
7*-(*AB+C
8D-(*AB+CD
9/-(/AB+CD*
10E-(/AB+CD*E
11+-(+AB+CD*E/
12F-(+AB+CD*E/F
13)-AB+CD*E/F+
14--AB+CD*E/F+-
15G-AB+CD*E/F+-G
16*-*AB+CD*E/F+-G
17H-*AB+CD*E/F+-GH
end(pop all)(empty)AB+CD*E/F+-GH*-

Answer: AB+CD*E/F+-GH*-

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 2 questions →