Skip to main content

Convert and evaluate A/B-(C+D)*E

Short answer

Postfix: AB/CD+E*-. Evaluating with A=8, B=2, C=3, D=1, E=1 yields 0.

Convert the given infix expression A/B-(C+D)*E into equivalent postfix expression showing each step in tabular form and evaluate the obtained postfix expression showing STACK status each time when A=8, B=2, C=3, D=1 and E=1.

Conversion of A / B − (C + D) * E

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+
10*-*AB/CD+
11E-*AB/CD+E
end(pop all)(empty)AB/CD+E*-

Postfix: AB/CD+E*-

Evaluation with A = 8, B = 2, C = 3, D = 1, E = 1

StepSymbolActionStack (bottom → top)
1Apush 88
2Bpush 28, 2
3/pop 2 (right), 8 (left); 8 / 2 = 4; push4
4Cpush 34, 3
5Dpush 14, 3, 1
6+pop 1 (right), 3 (left); 3 + 1 = 4; push4, 4
7Epush 14, 4, 1
8*pop 1 (right), 4 (left); 4 * 1 = 4; push4, 4
9-pop 4 (right), 4 (left); 4 - 4 = 0; push0

Answer: 0. Check: 8/2 − (3+1)*1 = 4 − 4 = 0.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 2 questions →