Computer Science
Convert the following infix notation to postfix notation, showing stack and string contents at each step.
A + B - C * D
Python Stack
2 Likes
Answer
Given,
A + B - C * D
Scanning from left to right :
| Symbol | Action | Stack | Postfix Expression |
|---|---|---|---|
| A | A | ||
| + | Push in stack | + | |
| ↑ | |||
| B | AB | ||
| - | Equal precedence to +. Pop from stack, add in expression then push this operator(-) | - | AB+ |
| ↑ | |||
| C | AB+C | ||
| * | Higher precedence than (-), hence Push | * - | |
| ↑ | |||
| D | AB+CD | ||
| End of expression | Pop all and add to expression | #Empty | AB+CD*- |
Postfix notation of A + B - C * D = AB+CD*-
Answered By
1 Like
Related Questions
Evaluate following postfix expression while showing status of stack after each operation given A = 3, B = 5, C = 1, D = 4.
AB + C *
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 * (( C + D)/E)
Write a program to create a Stack for storing only odd numbers out of all the numbers entered by the user. Display the content of the Stack along with the largest odd number in the Stack. (Hint. Keep popping out the elements from stack and maintain the largest element retrieved so far in a variable. Repeat till Stack is empty)