Thursday, 17 January 2013

Infix to Prefix Conversion


By on 01:34

Infix expression are those expression in which its form look like as a*b+c/d*e-f~g+h and Prefix expression are those expression in which its form/notation look like as abc*d-ef+*+gh~.It is used in c,c++,java,c#(or data structure) etc.

Example(Direct/Shortcut Method):-

-->i+j*k/l-m~n+o

=i+(*jk)/l-m~n+o
=i+(/*jkl)-(~mn)+o
=(+i/*jkl)-(~mn)+o
=(-+i/jkl~mn)+o
=+-+i/jkl~mno....................Prefix Expression

Examples(by algorithm/stack method):-

-->g+a+(b-c)*d(written in backward direction)

Infix Stack Prefix
d
d
* * d
) *) d
c *) dc
- *)- dc
b *)- dcb
( * dcb-
+ + dcb-*
a + dcb-*a
+ ++ dcb-*a
g
dcb-*ag++

=++ga*-bcd(ans.)


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...