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=)

pseudorandom21 commented: Why do you expect others to do work for you because you post on a forum? +0

Recommended Answers

All 5 Replies

what is the question???? what do you need help with?

#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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.