Q8,p2,d14. How many PUSH and POP operations will be needed to evaluate the following expression by reverse polish notation in a stack machine (A ∗B) + (C ∗D/E) ?
Reverse Polish Notation==> 1. Avoid Brackets 2. Convert into post fix Therefore, Normal Expression is (A*B)+(C*D/E) Post fix notation without brackets AB*CDE/*+
When an operand or operands appear push it or them on the top of stack. When a binary operator appears pop two operands from the stack. Compute the result and push the result on the top of stack. According to given expression:
1. Push A,B 2. * operator appears so Pop A,B 3. Push the result of above computation, say R1, on top of stack. 4. Push C,D,E. 5. / operator appears so Pop D,E. 6. Push the result R2 on the top of stack. 7. * operator appears so Pop R2,C. 8. Push the result R3 on the top of stack. 9. + operator appears so Pop R3, R1.
can anyone explian please....am not understanding
ReplyDeleteReverse Polish Notation==> 1. Avoid Brackets
ReplyDelete2. Convert into post fix
Therefore,
Normal Expression is (A*B)+(C*D/E)
Post fix notation without brackets AB*CDE/*+
When an operand or operands appear push it or them on the top of stack.
When a binary operator appears pop two operands from the stack. Compute the result and push the result on the top of stack.
According to given expression:
1. Push A,B
2. * operator appears so Pop A,B
3. Push the result of above computation, say R1, on top of stack.
4. Push C,D,E.
5. / operator appears so Pop D,E.
6. Push the result R2 on the top of stack.
7. * operator appears so Pop R2,C.
8. Push the result R3 on the top of stack.
9. + operator appears so Pop R3, R1.
Hence 5 push and 4 pop operations.
wrong process
DeleteFor other topics of Computer Science
ReplyDeletehttp://graspandsprout.blogspot.in/