Skip to main content

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

Short answer

Postfix: AB+CD-*. Evaluating with A=5, B=7, C=9, D=4 yields 60.

Convert the given infix expression (A+B)*(C-D) into equivalent postfix expression showing each step in tabular form and evaluate the obtained postfix expression showing STACK status each time when A=5, B=7, C=9 and D=4.

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

StepSymbolStack (bottom → top)Postfix output
1((-
2A(A
3+(+A
4B(+AB
5)(empty)AB+
6**AB+
7(*(AB+
8C*(AB+C
9-*(-AB+C
10D*(-AB+CD
11)*AB+CD-
end(pop all)(empty)AB+CD-*

Postfix: AB+CD-*

Evaluation with A = 5, B = 7, C = 9, D = 4

StepSymbolActionStack (bottom → top)
1Apush 55
2Bpush 75, 7
3+pop 7 (right), 5 (left); 5 + 7 = 12; push12
4Cpush 912, 9
5Dpush 412, 9, 4
6-pop 4 (right), 9 (left); 9 - 4 = 5; push12, 5
7*pop 5 (right), 12 (left); 12 * 5 = 60; push60

Answer: 60. Check: (5+7) × (9−4) = 12 × 5 = 60.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 2 questions →