Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

T0PIC

INFIX TO POSTFIX
PRESENTED BY
Y.KARUNA SRI
23B81A05LM
Infix Expression: A + B*C

 INFIX EXPRESSION:An infix expression is a type of notation


commonly used in arithmetic and algebra where operators are
placed between the operands they operate on.
EXAMPLE:A+B*C

 POSTFIX EXPRESSION:A postfix expression (or Reverse Polish Notation)


is a way of writing arithmetic expressions where the operator comes
after the operands.
EXAMPLE:ABC*+
•Left Left
Parenthesis (
Parenthesis (: Push
: Push it onto
it onto the stack.
the stack.
•Left Parenthesis (: Push it onto the stack.

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

You might also like