Waht's wrong with the code. It gives "compile error" without error message.


  • 0
    H

    It throws out "compile error" without error message. Can someone tell me what is wrong with this code?

    class Solution {
        public:
            vector<int> diffWaysToCompute(string input) {
                vector<int> findresult(vector<int>,vector<char>,vector<int>::size_type,vector<int>::size_type);
                vector<int> operation(vector<int>,vector<int>,char);
                vector<int> number;
                vector<char> oper;
                for(string::size_type i=0;i<input.size();++i){
                    switch (input[i]){
                        case '+': oper.push_back(input[i]);
                        break;
                        case '-': oper.push_back(input[i]);
                        break;
                        case '*': oper.push_back(input[i]);
                        break;
                        default: number.push_back(input[i]-'0');
                        break;
                    }
                }
                vector<int>::size_type sz=number.size();
                return findresult(number,oper,0,sz-1);
            };
            
            vector<int> findresult(vector<int> number, vector<char> op, vector<int>::size_type p, vector<int>::size_type q){
                vector<int> operation(vector<int>,vector<int>,char);
                vector<int> ret;
                if(p==q){
                    ret.push_back(number[p]);
                    return ret;
                }else{
                    for(vector<int>::size_type i=p;i<q;++i){
                        vector<int> left, right, A;
                        left=findresult(number,op,p,i);
                        right=findresult(number,op,i+1,q);
                        A = operation(left,right,op[i]);
                        for(vector<int>::size_type j=0;j<A.size();++j){
                            ret.push_back(A[j]);
                        }
                    }
                    return ret;
                }
            };
            
            vector<int> operation(vector<int> numberleft, vector<int> numberright, char op){
                vector<int> ret;
                for(vector<int>::size_type i=0;i<numberleft.size();++i){
                    for(vector<int>::size_type j=0;j<numberright.size();++j){
                        switch (op){
                            case '+': ret.push_back(numberleft[i]+numberright[j]);
                            break;
                            case '-': ret.push_back(numberleft[i]-numberright[j]);
                            break;
                            case '*': ret.push_back(numberleft[i]*numberright[j]);
                            break;
                        }
                    }
                }
                return ret;
            }
        };

  • 0
    Y

    vector<int> findresult(vector<int> number, vector<char> op, vector<int>::size_type p, vector<int>::size_type q){
    vector<int> operation(vector<int>,vector<int>,char); <==== what do you mean here?
    vector<int> ret;


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.