Professional Documents
Culture Documents
23B81A05LM DSC
23B81A05LM DSC
INFIX TO POSTFIX
PRESENTED BY
Y.KARUNA SRI
23B81A05LM
Infix Expression: A + B*C
Initialize:
Create an empty stack for operators.
Create an empty list for the output (postfix expression
Operand (numbers or variables):
Add it directly to the output list.
Left Parenthesis (: Push it onto the stack
Right parenthesis ):pop from the stack and add to the output list untile a left a
parenthesis is encountered.Discard the left parenthesis.
Operator(+,-,*,/):
while the stack is not empty the top of the stack has an operator of higher or
equal precedence pop from the stack to the output list.
Push the operator stack onto the stack.
After reading the entire expression:
pop all the operators into the output list.
Precendence:
exponential(^):higher precedence
multiplication(*)and division(/):next higher precedence.
addition(+) and subtraction(-):low precedence.
Infix Expression: A + (B * C - D) / (E - F)
SYMBOL STACK POSTFIX
A - A
+ A
+
( +( A
B +( AB
* +(* AB
C +(* ABC
- +(- ABC*
SYMBOL STACK POSTFIX
D +(- ABC*D
) + ABC*D-
/ +/ ABC*D-
( +/( ABC*D-
E +/( ABC*D-E
- +/(- ABC*D-E
F +/(- ABC*D-EF
) +/ ABC*D-EF-
ABC*D-EF-/+
THANKYOU