Can anyone spot the bug in my code?It works well in dev c++.
#include <bits/stdc++.h>
using namespace std;
stack b;
int value(char c)
{
if(c==’^’)
return 5;
if(c==’/’)
return 4;
if(c==’*’)
return 3;
if(c==’-’)
return 2;
if(c==’+’)
return 1;
if(c==‘c’)
return 10;
}
int main() {
int t;char p;string a;
cin>>t;
while(t–)
{
cin>>a;char l;char k;
for(int i=0;a[i]!=’\0’;i++)
{
if(a[i]==40)
{
b.push(a[i]);
}
if(a[i]==41)
{
l=b.top();
while(l!=40)
{
cout<<b.top();
b.pop();
}
b.pop();
}
if(a[i]==42||a[i]==43||a[i]==45||a[i]==47||a[i]==94)
{
if(!b.empty())
k=b.top();
else
k=‘c’;
if(value(k)<value(a[i]))
{
while (!b.empty())
{
cout<<b.top();
b.pop();
}
}
b.push(a[i]);
}
if(a[i]<123 && a[i]>96)
cout<<a[i];
}
while(!b.empty())
{
cout<<b.top();
b.pop();
}
cout<<endl;
}
return 0;
}