Infix To Postfix Conversion using Stack C Program

By | October 5, 2016

Learn how to convert an expression from Infix to Postfix using Stack in C Programming. This code for infix to postfix in c uses two arrays to store infix and postfix expression and a stack for conversion from infix to postfix expression.

What is Polish Notation?

A polish mathematician named Jan Lukasiewicz has given a method to represent arithmetic expressions. It included infix, postfix and prefix methods to represent an expression. The infix method is the conventional method to represent arithmetic expressions since it is better analyzed by the computers.

Infix To Postfix Conversion Example

Infix String: A+ B ^ C + D * E / (F + G)

Postfix String: ABC/+DE*_F+

Steps To Convert Infix Expression to Postfix Expression

1. Scan the symbols of the Infix string from left to right one by one.
• If the character is an operand then shift it to the postfix string (array).
• If the character is left parathesis then push it on the stack.
• If the character found is right parantheses then pop all the operators from the stack upto the first left parantheses and add all these operators to the postfix string. Now, delete the right and left parantheses.
• If the character is an operator then pop the operators that have the greater or equal precedence than the character operator and shift these popped operators to the postfix string. Now, push the scanned symbol operator on the stack.
2. After all the characters of the Infix string have been scanned, pop all the remaining operators on the stack and then shift them to postfix string.

Output

In case you get any compilation errors or any doubts in this C Program For Conversion of Infix Expression to Postfix Expression, let us know about it in the Comment Section below.

2 thoughts on “Infix To Postfix Conversion using Stack C Program”

1. Vivek Rathod

Best Program. Can we convert infix expression to postfix expression using linked list in c?

2. sidra noor

this program is too much difficult ..plz give me the concept about how to convert a infix to prefix or postfix