Infix To Postfix Conversion
Infix To Postfix Conversion
1. Put the open and close parenthesis/delimeter at the start and end of the Infix
Expression.
2. Read the Infix string from left to Right.
3. Initialize an empty stack.
4. If the scanned character is an operand, add it to the OUTPUT Postfix string.
5. If the scanned character is an operator and if the stack is empty push the
character to stack.
6. If the scanned character is an Operator and the stack is not empty, compare the
precedence of the character with the element on top of the stack.
7. If top Stack has higher precedence over the scanned character pop the stack else
push the scanned character to stack. Repeat this step until the stack is not empty
and top Stack has precedence over the character.
8. Repeat 4 and 5 steps till all the characters are scanned.
9. After all characters are scanned, we have to add any character that the stack may
have to the Postfix string.
10. If stack is not empty add top Stack to Postfix string and Pop the stack.
11. Repeat this step as long as stack is not empty.
Conversion To Postfix
EXAMPLE: Infix String : A+(B*C-(D/E-F)*G)*H
Step-1: (A+(B*C-(D/E-F)*G)*H)
Output
Stack Input Description
(Postfix String)