In: Computer Science
2. Convert the following infix form expression into the postfix form expression by using a stack:
A+(B*(C-D)+E)/F-G*H
Show the stack after each push/pop.
Convert the infix to postfix expression:-
| Symbol | Stack | Postfix |
| A | ( | A |
| + | (+ | A |
| ( | (+( | A |
| B | (+( | AB |
| * | (+(* | AB |
| ( | (+(*( | AB |
| C | (+(*( | ABC |
| - | (+(*(- | ABC |
| D | (+(*(- | ABCD |
| ) | (+(* | ABCD- |
| + | (+(+ | ABCD-* |
| E | (+(+ | ABCD-*E |
| ) | (+ | ABCD-*E+ |
| / | (+/ | ABCD-*E+ |
| F | (+/ | ABCD-*E+F |
| - | (- | ABCD-*E+F/+ |
| G | (- | ABCD-*E+F/+G |
| * | (-* | ABCD-*E+F/+G |
| H | (-* | ABCD-*E+F/+GH |
| ) | ABCD-*E+F/+GH*- |
Here we are Assuming the brackets outside the whole expression by default to convert it into postfix.