Stacks- Postfix to Infix

Sandhya Reyya
1 min readDec 22, 2020

--

Infix- It is an expression where the operator lies between operators.

e. g. : a + b

Postfix: Postfix is an expression where the operators are placed next to the operands.

e. g. : ab+

Postfix is computer understandable format but it is not that efficient for humans to read. Humans can understand infix format efficiently than postfix.

In my previous stories we have seen the conversion of an expression from infix to prefix /postfix . But here we will see the conversion of postfix expression to infix expression.

Let us see the algorithm for the conversion of an expression from postfix to infix.

Algorithm:

  • Start.
  • Read the postfix expression from user.
  • Check the expression character by character
  • If the character is an operand , then it is pushed into the stack.
  • If the character is an operator, then pop the top 2 data items , insert the operator between the 2 data items.
  • Push the expression again into the stack.
  • Continue this process , until the stack contains only one data item.
  • Pop and write the data item from the stack which is the infix expression.
  • Stop.

The above is the algorithmic approach and now let’s see the programming approach:

C:

This is the description of an expression converting from postfix format to infix format. In the very next story we can note regarding conversion of an expression from prefix to infix.

Thank you.

--

--

Sandhya Reyya
Sandhya Reyya

No responses yet