Myrecursive solution!


#1

int recur(stack &s)
{
if (s.empty())
return 1;
else if(s.top()=="+")
{
s.pop();
int a = recur(s);
s.pop();
return recur(s) + (a);
}
else if(s.top()=="-")
{
s.pop();
int a = recur(s);
s.pop();
return recur(s) - (a);
}
else if(s.top()=="*")
{
s.pop();
int a = recur(s);
s.pop();
return recur(s) * (a);
}
else if(s.top()=="/")
{
s.pop();
int a = recur(s);
s.pop();
return recur(s) / (a);
}
else
return stoi(s.top());

}
int Solution::evalRPN(vector &A)
{
stack s;
int i;
for(i=0;i<A.size();i++)
{
s.push(A[i]);
}
int ans = recur(s);
return ans;
}