Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 885 Bytes

3.md

File metadata and controls

39 lines (29 loc) · 885 Bytes
 long resolves(int a, int b, string Operator){
        if(Operator == "+") return a + b;
        else if(Operator == "-") return a - b;
        else if(Operator == "*") return (long)a*b;
        return a/b;
    }

    int evalRPN(vector<string>& tokens) {
        
        stack<long>s;

        for(auto str:tokens)
        {
            if(isdigit(str[0]) || (str.size() > 1))
            {
                s.push(stoi(str));
            }

            else
            {
                int right=s.top();
                s.pop();

                int left=s.top();
                s.pop();

                long output=resolves(left,right,str);
                s.push(output);
            }
        }


        return s.top();
    }