recategorized by
2,676 views

1 Answer

Best answer
1 votes
1 votes

Following is algorithm for evaluation postfix expressions.

1) Create a stack to store operands (or values).

2) Scan the given expression and do following for every scanned element.

  • a) If the element is a number, push it into the stack
  • b) If the element is a operator, pop operands for the operator from stack.

           ​Evaluate the operator and push the result back to the stack 

3) When the expression is ended, the number in the stack is the final answer

Postfix Expression=a b c d + - *

=a b ( c + d ) - *

=a ( b - ( c + d ) ) *

=( a * ( b - ( c + d ) ) )

Now Put the values a=8 ,b=4 c=2 and d=5

 ( 8 * ( 4 - ( 2 + 5 ) ) )

( 8 * ( 4 - ( 7) ) )

 =( 8 * ( -3 ) )

=-24

Hence,Option(D)-24 is the correct choice.

selected by
Answer:

Related questions

2 votes
2 votes
1 answer
2
go_editor asked Jul 25, 2016
2,175 views
Which of the following has compilation error in C?int n=32 ;char ch=65 ;float f=(float) 3.2 ;none of the above
0 votes
0 votes
2 answers
3
go_editor asked Jul 25, 2016
3,316 views
What does the following declaration mean? int (*ptr) [10];ptr is an array of pointers of 10 integersptr is a pointer to an array of 10 integersptr is an array of 1...
0 votes
0 votes
2 answers
4
Sanjay Sharma asked Apr 25, 2016
4,480 views
The correct way to round off a floating number x to an integer value isy = (int) (x + 0.5)y = int (x + 0.5)y = (int) x + 0.5y = (int) ((int)x + 0.5)