0% found this document useful (0 votes)
130 views24 pages

Infix To Postfix

This document discusses converting infix expressions to postfix expressions. It defines infix, postfix, and prefix notation and provides examples. The components needed for conversion are an input vector, stack, and output vector. Rules for conversion include adding operands to the output, handling parentheses, and evaluating operator precedence. The document walks through converting the expression (a+b-c)*d–(e+f) to postfix notation step-by-step to demonstrate the conversion process.

Uploaded by

syamradhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views24 pages

Infix To Postfix

This document discusses converting infix expressions to postfix expressions. It defines infix, postfix, and prefix notation and provides examples. The components needed for conversion are an input vector, stack, and output vector. Rules for conversion include adding operands to the output, handling parentheses, and evaluating operator precedence. The document walks through converting the expression (a+b-c)*d–(e+f) to postfix notation step-by-step to demonstrate the conversion process.

Uploaded by

syamradhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Lecture

ON

Basics of Expression &How to


convert an Infix expression to
Postfix expression

V.Radhesyam
Assistant professor
Department of IT:VRSEC
Expressions

 What is an expression?
An expression is a legal combination of operands and
operators.
­ (A+B)­-C
(4/­5)*(10+6)
 Operands means
variable like x,y,z or constant like 5,4,0,2
 Operator means
symbol like +,­,*,/ used with operands.
 

Radhesyam.V 2
Expression representation

 How to represent expressions


Expressions can be represented in three ways.
 INFIX Operator is between operands normal human
readable
 POSTFIX Operator is after operands
 PREFIX Operator is before operands
 Both POSTFIX and PREFIX are used by computer
systems to evaluate expressions and these does not
have parenthesis.

Radhesyam.V 3
Examples

Infix Postfix Prefix

A+B AB+ +AB

(A+B)*C AB+C* *+ABC

(A+B)*(C+D) AB+CD+* *+AB+CD

Radhesyam.V 4
Components needed

 List the components required to convert INFIX to


POSTFIX conversion.?
 Three components are required
 Input vector
 Stack
 Output vector

Radhesyam.V 5
Rules to Convert Infix to Postfix
Expression
 When the token is operand add it to the end of output
 A left parenthesis: Push it onto the stack
 A right parenthesis: Pop and display stack element until
a left parenthesis is encountered. And discard pair of parenthesis
 If Stack is empty or incoming symbol has high precedence than
TOS :push it on to the Stack.
 If incoming symbol has low precedence (equal) than TOS :Pop the
stack and TOS.
 A left parenthesis in the stack is assumed to have lower priority
than that of operators

Radhesyam.V 6
Precedence

Division -> Multiplication -> Addition -> Subtraction


[MAX. PRIORITY] ---------------------[MIN. PRIORITY]
^ / % * + -
Examples
3+4*5/6 , 3 4 5 * 6 / +
a+b*c-d , abc*+d-

Radhesyam.V 7
Infix to postfix conversion

infixVect
(a+b-c)*d–(e+f)

postfixVect

Radhesyam.V
Infix to postfix conversion

infixVect
a+b-c)*d–(e+f)

postfixVect

( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
+b-c)*d–(e+f)

postfixVect
a

( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
b-c)*d–(e+f)

postfixVect
a

+
( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
-c)*d–(e+f)

postfixVect
ab

+
( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
c)*d–(e+f)

postfixVect
ab+

-
( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
)*d–(e+f)

postfixVect
ab+c

-
( stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
*d–(e+f)

postfixVect
ab+c-

stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
d–(e+f)

postfixVect
ab+c-

* stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
–(e+f)

postfixVect
ab+c-d

* stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
(e+f)

postfixVect
ab+c–d*

- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
e+f)

postfixVect
ab+c–d*

(
- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
+f)

postfixVect
ab+c–d*e

(
- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
f)

postfixVect

+ ab+c–d*e

(
- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect
)

postfixVect

+ ab+c–d*ef

(
- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect

postfixVect
ab+c–d*ef+

- stackVect

Radhesyam.V
Infix to postfix conversion

infixVect

postfixVect
ab+c–d*ef+-

stackVect

Radhesyam.V

You might also like