Thursday, 17 January 2013

Postfix Evaluation


By on 09:04

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

-->2*5/3-7+8%3*2-1(by using stack algorithm)

First we evaluate infix expression(direct method):-

=10/3-7+8%3*2-1
=3-7+8%3*2-1
=3-7+2*2-1
=3-7+4-1
=-4+4-1
=-1

Then Convert into Postfix notation:-

=(25*3/)-7+(83%)*2-1
=(25*3/)-7+(83%2*)-1
=(25*3/7-)+(83%2+)-1
=(25*3/7-83%2*+)-1
=25*3/7-83%2*+1-

Finally Postfix conversion by using stack:-

Postfix Stack
2 2
3 2,3
5 2,3,5
* 2,15
4 2,15,4
- 2,11
3 2,11,3
% 2,2
+ 4
7 4,7
- -3
1 -3,1
5 -3,1,5
* -3*5
+ 2


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