Thursday, 17 January 2013

Prefix Evaluation


By on 09:26

After discussing Infix to Postfix ,Infix to Prefix and Postfix evaluation,now I discuss Prefix Evaluation.Prefix evaluation can be done in c,c++,java,c# etc.Now we take an example:-

-->2+(3*5)%4-7*(2+3)


First we evaluate Prefix expression(direct method):-

2+(15)%4-7*(5)

=2+3-35
=5-35
=-30


Then Convert into Prefix notation:-

=2+(*35)%4-7*(+23)

=2+(%*354)-7*(+23)
=2+(%*354)-(*7+23)
=(+2%*354)-(*7+23)
=-+2%*354*7+23

Finally Prefix conversion by using stack algorithm:-


Prefix Stack
3 3
2 3,2
+ 5
7 5,7
* 35
4 35,4
5 35,4,5
3 35,4,5,3
* 35,4,15
% 35,3
2 35,3,2
+ 35,5
- -30



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...