Explain the algorithm to convert infix expression to postfix.
Answers
Answered by
1
Push “(“onto Stack, and add “)” to the end of X.
Scan X from left to right and repeat Step 3 to 6 for each element of X until the Stack is empty.
If an operand is encountered, add it to Y.
If a left parenthesis is encountered, push it onto Stack.
If an operator is encountered ,then:
Repeatedly pop from Stack and add to Y each operator (on the top of Stack) which has the same precedence as or higher precedence than operator.
Add operator to Stack.
[End of If]
If a right parenthesis is encountered ,then:
Repeatedly pop from Stack and add to Y each operator (on the top of Stack) until a left parenthesis is encountered.
Remove the left Parenthesis.
[End of If]
[End of If]
END.
Similar questions
Physics,
6 months ago
English,
6 months ago
English,
6 months ago
Computer Science,
1 year ago
Science,
1 year ago
Social Sciences,
1 year ago