Stacks- Infix to Prefix Conversion

Sandhya Reyya
1 min readDec 3, 2020

--

Computer can even understand prefix expression easily. Prefix is exactly opposite to postfix expression. Prefix expression is defined in such a way, where the operators comes first and then the operands follow.

e. g. : +ab

If we know how to convert an expression from infix to postfix, then it is very easy to convert from infix to prefix. Let us see the algorithm for the expression conversion from infix to postfix.

Algorithm

  • Start.
  • Read the infix expression.
  • Reverse the infix expression.
  • Convert the reversed infix expression to postfix expression.
  • Now reverse the obtained postfix expression which is actually a prefix expression.
  • Write the prefix expression .
  • Stop.

Now let us see the program on the conversion of an infix expression to prefix expression.

C:

To recheck the conversion from infix to postfix , you can check my previous story

In my next story, we will convert an expression from postfix to infix.

Thank you.

--

--

Sandhya Reyya
Sandhya Reyya

No responses yet