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 *
Python Stack
4 Likes
Answer
AB + C * = 35 + 1 *
Scanning from left to right :
| Symbol | Action | Stack | Intermediate output |
|---|---|---|---|
| 3 | Push | 3 | |
| ↑ | |||
| 5 | Push | 5 3 | |
| ↑ | |||
| + | Pop twice and Evaluate and Push back | #Empty | 3 + 5 = 8 |
| 8 | |||
| ↑ | |||
| 1 | Push | 1 8 | |
| ↑ | |||
| * | Pop twice, Evaluate Push back | #Empty | 1 * 8 = 8 |
| 8 | |||
| ↑ |
Hence, AB + C * = 35 + 1 * = 8
Answered By
1 Like
Related Questions
Write a program to reverse a string using stack.
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 / D *
Convert the following infix notation to postfix notation, showing stack and string contents at each step.
A + B - C * D