Computer Science

Convert the following infix notation to postfix notation, showing stack and string contents at each step.

A + B - C * D

Python Stack

2 Likes

Answer

Given,

A + B - C * D

Scanning from left to right :

SymbolActionStackPostfix
Expression
AA
+Push in stack+
BAB
-Equal precedence to +. Pop from stack, add in expression then push this operator(-)-AB+
CAB+C
*Higher precedence than (-), hence Push* -
DAB+CD
End of expressionPop all and add to expression#EmptyAB+CD*-

Postfix notation of A + B - C * D = AB+CD*-

Answered By

1 Like


Related Questions