Why am i getting this error ? terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc


#1

when i’m using custom input of [2,2,/] i’m getting 1 but on submitting i’m getting
terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc
my code
int isoperand(string x)
{
if(x=="+"||x=="-"||x==""||x=="/") return 0;
else return 1;
}
int Solution::evalRPN(vector &A) {
int x1=0,x2=0,z=0,r=0;
stacks;
for(int i=0;A[i]!="\0";i++)
{
if(isoperand(A[i]))
{
s.push(atoi(A[i].c_str()));
}
else
{
x2=s.top();
s.pop();
x1=s.top();
s.pop();
switch(A[i][0])
{
case ‘+’: r=x2+x1; break;
case ‘-’: r=x1-x2; break;
case '
’: r=x2*x1; break;
case ‘/’: r=x1/x2; break;
}
s.push®;
}
}
return s.top();
}