64,648
社区成员
发帖
与我相关
我的任务
分享
string& removeSpaceCopy(string& dest, const string& src);
void getOperand(vector<string>& operandVec, char*& p, bool startWithSign = false);
bool isParenthese(c);
bool isOperator(c);
void separate(vector<string>& operandVec, vector<char>& operatorVec, const string& src)
{
string exp;
removeSpaceCopy(exp, src);
char *p, c;
for(p = exp.c_str(); c = *p; ){
if(isdigit(c)) getOperand(operandVec, p);
else if(isParenthese(c)){
operatorVec.push_back(c);
++p;
}
else if(isOperator(c)){
if(!operatorVec.empty() && operatorVec.back() == '('){
if(c == '+' || c == '-') getOperand(operandVec, p, true);
else{
//illegal expression
}
}
else{
operatorVec.push_back(c);
++p;
}
}
else{
//illegal expression
}
}
}