Prefix to Infix Conversion

 Steps to convert prefix expression to infix

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

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

  3. 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.

  4. Now push this resulting string back into the stack.

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

 

 Conversion of Prefix to Infix using Stack

 * - A / B C - / A K L

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

No comments:

Post a Comment