Postfix/Prefix to Infix converter

We have two converters. The first converter converts postfix to infix expression. And the second one converts prefix to infix expression.

You will get step by step conversion for your postfix/prefix expression to infix form.

1. Postfix to Infix converter step by step

The following converter converts an postfix expression to a infix expression.

Change the expression and converter will convert postfix to infix step by step.

Postfix:

Infix:

How to convert postfix to infix?

  • Scan the given postfix expression from left to right character by character.

  • If the character is an operand, push it into the stack.

  • But if the character is an operator, pop the top two values from stack.

    Concatenate this operator with these two values (2nd top value+operator+1st top value) to get a new string.

  • Now push this resulting string back into the stack.

  • Repeat this process untill the end of postfix expression. Now the value in the stack is the infix expression.

Input StringPostfix ExpressionStack (Infix)

2. Prefix to Infix converter step by step

The following converter converts an prefix expression to a infix expression.

Change the expression and converter will convert prefix to infix step by step.

Prefix:

Infix:

How to convert prefix to infix?

  • Scan the given prefix expression from right to left character by character.

  • If the character is an operand, push it into the stack.

  • But if the character is an operator, pop the top two values from stack.

    Concatenate this operator with these two values (1st top value+operator+2nd top value) to get a new string.

  • Now push this resulting string back into the stack.

  • Repeat this process untill the end of prefix expression. Now the value in the stack is the desired infix expression.

Input StringPrefix ExpressionStack (Infix)

Was this article helpful?