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