how do i evaluate the following two expressions??
9 8 2 - 3 / +
I come up with
9 - 8 = 1 / 2 = .5 + 3 = 3.5
3 4 5 2 * - +
I come up with
3 * 4 = 12 - 5 = 7 + 2 = 9
Am I doing this right when talking of binary tree postfix expressions???
how do i evaluate the following two expressions??
9 8 2 - 3 / +
I come up with
9 - 8 = 1 / 2 = .5 + 3 = 3.5
3 4 5 2 * - +
I come up with
3 * 4 = 12 - 5 = 7 + 2 = 9
Am I doing this right when talking of binary tree postfix expressions???
9 8 2 - 3 / +
Actually, I believe to be totally postfix, it would be:
9 8 2 3 / + -
Which would be:
9 - 8 = 1
1 / 2 = .5
.5 - 3 = -2.5
But I could be wrong. I've personally never had use for postfix notations.
Quzah.
Hope is the first step on the road to disappointment.
The best way to do this is just look at it one operator at a time...
First we just have some numbers...
9 8 2
then we get a '-', which operates on the last 2 values...
9 (8, 2)-
now, (8, 2)- is a value, that is, it represents 6. We could just replace (8, 2)- with 6 at this point, but I don't for the purpose of showing how postfix is changed to other forms.
another number....
9 (8, 2)- 3
and an operator that will work on the last 2 values
9 ((8, 2)-, 3)/
and another operator that will work on the last 2 values...
(9, ((8, 2)-, 3)/)+
Now we just break it down into infix using the parenthesis...
(9 + ((8 - 2) / 3))
And that's how you analyze it.
Or, just replacing the values, it would analyze like this...
9 8 2 - == 9 6
9 6 3 / == 9 2
9 2 + == 11
11 nothing left, so 11's the answer.
Callou collei we'll code the way
Of prime numbers and pings!
so with your logic explained would the second expression i have
3 4 5 2 * - +
be.......
3, 4 (5,2) *
3,(4,(5,2)*)-
(3,(4,(5,2)*)-)+
(3 + (4 - (5*2))) = -3
Exactly.
Callou collei we'll code the way
Of prime numbers and pings!