Learn How To Convert Postfix To Prefix Notation using Stack in C Programming Language. Before you proceed further with this code, you must know the complete operations of stack data structure.
The Postfix notation is also known as Reverse Polish Notation and the Prefix notation is also known as Polish Notation.
Postfix To Prefix Conversion Example
Postfix String: 44+
Prefix String: +44
Algorithm To Convert Postfix Expression into Prefix Notation
- Scan the Postfix Expression from Left To Right.
- If the character is an Operand, then Push it on to the Stack.
- If the character is an Operator, then Pop Operand 1 and Operand 2 and concatenate them and Push the result on the Stack.
- Repeat the above steps until the Postfix Expression is scanned completely.
- To get the Prefix Expression, Pop the remaining elements of the Stack.
C Program For Postfix To Prefix Conversion using Stack Data Structure
#define MAX 20
char str[MAX], stack[MAX];
int top = -1;
void push(char ch)
stack[++top] = ch;
void postfix_to_prefix(char expression)
int count, length;
length = strlen(expression);
for(count = length - 1; count >= 0; count--)
printf("\nEnter Postfix Expression:\t");
In case you get any compilation errors or any doubts in this C Program For Conversion of Postfix Expression into Prefix Expression, let us know about it in the Comment Section below.