Advertisements
Advertisements
Question
Convert the following infix notations to postfix notations, showing stack and string contents at following step.
A + B - C * D
Answer in Brief
Advertisements
Solution
Infix Expression is : A + B - C * D
Scanning from Left to Right
| Symbol | Action | Stack, Initially Stack is Empty [ ] | Postfix Expressions |
| A | Append to Postfix Expression | [ ] | A |
| + | PUSH(‘+’) | + | A |
| B | Append to Postfix Expression | + | A B |
| – | – have equal precedence to +. First POP(‘+’) then PUSH(‘-‘) | – | A B + |
| C | Append to Postfix Expression | – | A B + C |
| * | * have higher precedence than -, PUSH ‘*’ | – * | A B + C |
| D | Append to Postfix Expression | – * | A B + C D |
| End of Expression | POP all and add to Postfix Expression | [ ] | A B + C D * – |
shaalaa.com
Conversion from Infix to Postfix Notation
Is there an error in this question or solution?
