-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPrefix_To_Infix.cpp
More file actions
32 lines (32 loc) · 946 Bytes
/
Copy pathPrefix_To_Infix.cpp
File metadata and controls
32 lines (32 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<stack>
#include<string>
using namespace std;
void prefix_to_infix(string s)
{
stack<int>s1;
string op1,op2;
string temp;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='^')
{
op1=s1.top();
s1.pop();
op2=s1.top();
s1.pop();
temp="("+op1+s[i]+op2+")";
s1.push(temp);
}
else
s1.push(s[i]);
}
cout<<"STRING:";
cout<<s1.top();
}
int main()
{
string s="K+L-M*N+(O^P)*W/U/V*T+Q";
prefix_to_infix(s);
return 0;
}