Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Data Structures and Algorithms

Lab 7

Infix to postfix Conversion

We have seen how to evaluate the postfix expressions while using the stack. How can we convert
the infix expression into postfix form? Consider the example of a spreadsheet. We must evaluate
expressions. The users of this spreadsheet will employ the infix form of expressions. Consider
the infix expressions ‘A+B*C’ and ‘(A+B)*C’. The postfix versions are ‘ABC*+’ and ‘AB+C*’
respectively. The order of operands in postfix is the same as that in the infix. In both the infix
expressions, we have the order of operands as A, B and then C. In the postfix expressions too,
the order is the same i.e. A, B, followed by C. The order of operands is not changed in postfix
form. However, the order of operators may be changed.

Now we will try to form an algorithm to convert infix form into postfix form. For this
purpose, a pseudo code will be written. You must write the loops and if conditions.
The pseudo code is independent of languages. You will be using a stack in this
algorithm. Here, the infix expression is in the form of a string. The algorithm is as
follows:
Data Structures and Algorithms
Lab 7

You might also like