This algorithm converts an infix notation arithmetic expression to postfix notation. It scans the infix expression from left to right, pushing operands and left parentheses to a stack and popping operators with higher precedence to output. When it encounters a right parenthesis, it pops operators until it reaches the matching left parenthesis.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
393 views3 pages
Algorithm To Convert Infix To Postfix
This algorithm converts an infix notation arithmetic expression to postfix notation. It scans the infix expression from left to right, pushing operands and left parentheses to a stack and popping operators with higher precedence to output. When it encounters a right parenthesis, it pops operators until it reaches the matching left parenthesis.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
Algorithm to convert Infix To Postfix
Let, X is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression Y.
1. Push “(“onto Stack, and add “)” to the end of X.
2. Scan X from left to right and repeat Step 3 to 6 for each element of X until the Stack is empty. 3. If an operand is encountered, add it to Y. 4. If a left parenthesis is encountered, push it onto Stack. 5. If an operator is encountered ,then: 1. 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. 2. Add operator to Stack. [End of If] 6. If a right parenthesis is encountered ,then: 1. Repeatedly pop from Stack and add to Y each operator (on the top of Stack) until a left parenthesis is encountered. 2. Remove the left Parenthesis. [End of If] [End of If] 7. END.
Infix Expression: A+ (B*C-(D/E^F)*G)*H, where ^ is an