Computer Science
Evaluate following postfix expression while showing status of stack after each operation given A = 3, B = 5, C = 1, D = 4.
AB * C / D *
Python Stack
1 Like
Answer
AB * C / D * = 35 * / 4 *
Scanning from left to right :
Symbol | Action | Stack | Intermediate output |
---|---|---|---|
3 | Push | 3 | |
5 | Push | 5 3 | |
↑ | |||
* | Pop twice, Evaluate and Push back | #Empty | 3 * 5 = 15 |
15 | |||
↑ | |||
1 | Push | 1 15 | |
↑ | |||
/ | Pop twice, Evaluate and Push back | #Empty | 15/1 = 15 |
15 | |||
↑ | |||
4 | Push | 4 15 | |
↑ | |||
* | Pop twice, Evaluate and Push back | #Empty | 15 * 4 = 60 |
60 | |||
↑ |
Hence, AB * C / D * = 35 * / 4 * = 60
Answered By
1 Like
Related Questions
For the following arithmetic expression:
((2 + 3) * (4 / 2)) + 2
Show step-by-step process for matching parentheses using stack data structure.
Evaluate following postfix expression while showing status of stack after each operation given A = 3, B = 5, C = 1, D = 4.
AB + C *
Convert the following infix notation to postfix notation, showing stack and string contents at each step.
A + B - C * D
Convert the following infix notation to postfix notation, showing stack and string contents at each step.
A * (( C + D)/E)