Reverse Polish Notation Double Division Error
I've written this relatively commonplace algorithm that parses a given
input and then converts it from infix to postfix.
The problem that I'm having deals with the order of events. It's possible
that I'm misunderstanding something about postfix operations...
Let's say I want to calculate 10/(2-4)/5 : The answer should be -1,
however, the answer I get is -25.
10,2,4,-,5,/,/
Why? Because my 'postfix' goes and does the -2/5 first, then divides
10/-.4, which is clearly wrong:
Is there something simple I'm missing?
No comments:
Post a Comment