Problem statement
Given an arithmetic expression in prefix notation , convert it into the equivalent infix notation.
Sample example :
Prefix Input : *a/bc/ade
Infix output : ((a(b/c))*((a/d)e))
Prefix input : *ab
Infix expression : (a*b)
Introduction to Arithmetic Notations
Any arithmetic expression consists of operands and operators . The way we arrange our operators and operands to write the arithmetic expression is called Notation .
There are three different notations for writing the Arithmetic expression :

Infix expression An expression is said to be in infix notation if the operators in the expression are placed in between the operands on which the operator works.
For example => a + b * c Infix expressions are easy to read ,write and understand by humans , but not by computer Itβs costly , in terms of time and space , to process Infix expressions 
Postfix expression (Reverse Polish Notation) An expression is said to be in postfix notation if the operators in the expression are placed after the operands on which the operator works. For example => abc*+ Itβs most used to notation for evaluating arithmetic expression

Prefix expression (or Polish Notation ) An expression is said to be in prefix notation if the operators in the expression are placed before the operands on which the operator works. For example => +a*bc
Precedence order and Associativity of Operators
Precedence  Type  Operators  Associativity 
1  Postfix  () [] > . ++ —  Left to Right 
2  Unary  + – ! ~ ++ — (type)* & sizeof  Right to Left 
3  Multiplicative  * / %  Left to Right 
4  Additive  + –  Left to Right 
5  Shift  <<, >>  Left to Right 
6  Relational  < <= > >=  Left to Right 
7  Equality  == !=  Left to Right 
8  Bitwise AND  &  Left to Right 
9  Bitwise XOR  ^  Left to Right 
10  Bitwise OR    Left to Right 
11  Logical AND  &&  Left to Right 
12  Logical OR    Left to Right 
13  Conditional  ?:  Right to Left 
14  Assignment  = += + *= /= %= >>= <<= &= ^= =  Right to Left 
15  Comma  ,  Left to Right 
In this article we are gonna talk about how to convert prefix expression into infix expression For the simplicity and understanding purpose , we will consider only β+β , ββ ,β/β , β*β , β(β and β)β .
Approach
For converting Prefix to infix we use a stack . The stack helps us store the operands . Whenever an operator is found , we pop two operands from the stack and push a new operand , which is the result of the current operator on the popped operands, into the stack with parenthesis . The final element at the top of the stack will be our infix expression .
Algorithm

Scan all symbols one by one from right to left in the given prefix expression .

If the reading symbol is an operand , push it into the stack .

If the reading symbol is an operator , then a. Pop two expression from the stack , operand1 and operand2 , which is operand for the current operator b. Push β(β + operand1 + operator + operand2 + β)β into the stack

If there is no symbol left then stop the process . Top of the stack will have the required infix expression .
NOTE : β+β denotes the concatenation of strings .
Prefix to infix conversion example with dry run
Implementation
#include <bits/stdc++.h> using namespace std; bool isOperand(char ch){ return (ch>='a' && ch<='z')  (ch>='A' && ch <='Z'); } string prefixToInfix(string prefix) { stack<string> st; int len = prefix.size(); for (int i = len  1; i >= 0; i) { if(isOperand(prefix[i])){ st.push(string(1,prefix[i])); } else{ string operand1=st.top(); st.pop(); string operand2=st.top(); st.pop(); st.push("(" + operand1 + string(1,prefix[i]) + operand2 + ")"); } } return st.top(); } int main() { string prefix="*a/bc/ade"; string infix=prefixToInfix(prefix); cout<<"Prefix expression : "<<prefix<<endl; cout<<"Infix expression : "<<infix<<endl; return 0; }
This article tried to discuss Prefix to Infix conversion. Hope this blog helps you understand and solve the problem. To practice more problems you can check out MYCODE  Competitive Programming at PrepBytes.