Q. Let P be the postfix arithmetic expression: 7, 2,-, 1, 14, 1, 2, * Evaluate P using stack and showing the status of the stack at every step.


Answer =

2

Explanation :

1. Push 7 onto the stack.

2. Push 2 onto the stack.

3. Push - onto the stack.

3. Pop the top two values from the stack (2 and 7).

4. Perform the subtraction (7 - 2 = 5).

5. Push the result (5) back onto the stack.

6. Push 1 onto the stack.

7. Push 14 onto the stack.

8. Push 1 onto the stack.

9. Push 2 onto the stack.

10. Push * onto the stack.

11. Pop the top two values from the stack (2 and 1).

12. Perform the multiplication (1 * 2 = 2).

13. Push the result (2) back onto the stack.

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post