one way to eveluate a prefix expression is to use queue. to eveluate the expression scan it repeatedly untill you know the final expression value, read it repeatedly untill you know the final expression value. in each scan replace an operator followed by two operands by the calculated value.

for example,the following expression that is evaluated to 159:

- + * 9 + 2 8 * + 4 8 6 3

we can scan the expression and store it in a queue. during the scan, when the operator is followed by two operands, such as + 2 8,we put the result, 10 in the queue

after the first scan, we have
- + * 9 10 * 12 6 3

after the second scan we have
- + 90 72 3

after the third scan, we have
- 162

after the fourth scan, we have

hope you all can help=)

Votes + Comments
Why do you expect others to do work for you because you post on a forum?
7 Years
Discussion Span
Last Post by rahman86

#1 - Heading is bad. Next time put meaningful heading.
#2 - that sound like your homework. Why on earth will anyone do it for you?
Show efforts before shouting for help!

Edited by Stefano Mtangoo: n/a


not my homework just want to ask you all..
this is my own exercise..
and i'am don't know to do this..


You still need to ask a question. What is it specifically that you don't know how to do? What have you tried already?


plesae show us some of your coding first. Begging won't help.

Edited by rahman86: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.