**Application of Stacks.. Infix post and prefix**

*September 22, 2008.*

* Data Structure*

**Expression**:-collection of operators and operands is called expression.

i.e. in A+B A, B are operands and” +” is operator.

Types of Expression:

There are three types of Expression - Infix
- Postfix
- Prefix

*I)** Infix:*
In which operator is used between the operand

a+b

It is used in our common mathematical expressions.

* II) Postfix:*
In which operator is used after the operands.

i.e. ab+

* III) Prefix:*
In which the operator is used before the operands.

I .e. +ab

We use infix type in our daily life but the computer use the postfix or prefix, because it is easy for computer to calculate by using postfix or prefix.

Without the conversion of postfix and prefix is not possible

(Postfix ma jo show ho chukka ha usko prefix ma show krna ha to stack use krna para ga.)

Usually C++ programming used postfix but their use depends on the language creator, either he use postfix or prefix type.

Examples:

Consider the precedence of the operator, the precedence is decreasing downwardly.

( )

$ (this symbol is used for power symbol in the book of Tenun Baum and in shaum series the power symbol is denoted by a arrow with upward direction.)

/,* (both have same precedence)

+, _ (both have same precedence)

if there two operators with same precedence then computer start to solve the expression from left to right.

Examples of Postfix: 1) a+b-c

ab+ - c

ab+c- 2) a+b*c a + bc* (

we consider the ‘bc*’ one term and ’a’ other term and ‘+’ is operator between them and apply the postfix method.

aik color aik term o zahir krta ha.dusra color dusri term ko.in k dermean operators han.jesa k a+b-c men a, b, c alag alag tems han.ya colorz manta apko smjhana k ley dey han ta k apko alheda terms ka pata chal jay.sir na her term k nichy line lagwai thi ta k her term alheda ho jay and hamen asani sa smajh a jay. )

abc* +

3) (a+b)/ (e-f*c)

ab+ / (e-f*c) (idher a+b ma a, b alag alag terms thi.in k dermean + operator tha.operation k bad +ab ak term ban gai.Agy bhi yahi concept dea gaya ha.) ab+ / ( e-fc*)

ab+ / efc*-

ab+ efc*-/ 4) (a+b)/ (e$f*c)

ab+ / (ef$ * c)

ab+ / ef$c*

ab+ef$c*/ 5) a+b/d*e$f+g a+b/d*ef$ +g

a+ bd/ *ef$+g

a+ bd/ef$ *+g

abd/ef$* + + g

abd/ef$*+g+ 6) (a+b)/ (d*e$f+g) This is exercise for you; its prefix solution will be given at the end.

Example of Prefix: 1)

a+b === +ab 2) a+b-c

+ab - c

-+abc 3) a+b/d*e$f+g

a+b/d* $ef + g

a+/bd* $ef + g

a + */bd$ef + g

+a*/bd$ef + g

++a*/bd$efg 4)

(a+b)/ (d*e$f+g)

+ab/(d*$ef + g)

+ab /( *d$f + g)

+ab/ +*d$fg

/+ab+*d$fg