#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
bool opgreater(char ,char);
bool opgreater(char a ,char b)
{
if(a=='^')
return 1;
else
return((a=='*' || a== '/')>=(b=='*' || b=='/'));
}
int main()
{
int n;
scanf("%d",&n);
while (n--)
{
stack<char> exp;
string initial;
string final="";
int i=0;
bool x;
char temp,temp2;
getline(cin,initial,'\n');
initial+='\0';
while(initial[i]!='\0')
{
if(initial[i]=='^' ||initial[i]=='/'||initial[i]=='*'||initial[i]=='+'||initial[i]=='-')
{
while(!exp.empty() && exp.top()=='(')
{
temp2=exp.top();
x=opgreater(temp2,initial[i]);
if(x)
{
temp=exp.top();
exp.pop();
final+=temp;
}
else
{
exp.push(initial[i]);
break;
}
}
}
else if(initial[i]=='(')
exp.push(initial[i]);
else if(initial[i]==')')
{
while(exp.top()!='(')
{
temp=exp.top();
exp.pop();
final+=temp;
}
exp.pop();
}
else
{
final+=initial[i];
}
i++;
}
cout<<final;
}
}
I am encountering a segmentation fault when i run this program .. please help me..