Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

please help me..i don't how to do it.

  Asked By: Afiq    Date: Mar 21    Category: C++ Programming    Views: 636
  

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

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on please help me..i don't how to do it. Or get search suggestion and latest updates.




Tagged: