-2

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
159


hope you all can help=)

Votes + Comments
Why do you expect others to do work for you because you post on a forum?
5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by rahman86
0

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

Edited by Stefano Mtangoo: n/a

0

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

0

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

1

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.