bool GeneralUtils::Smaller(Point2f p1, Point2f p2, float delta) { if (Smaller(p1.y, p2.y, delta)) { return true; } else if (Bigger(p1.y, p2.y, delta)) { return false; } return Smaller(p1.x, p2.x, delta); }
void LongNum_division (LongNum **num1, LongNum **num2, LongNum **result) { node *temp1 = (*num1)->digits; node *temp2 = (*num2)->digits; int count = 0; if (Bigger ((*num1)->digits,(*num2)->digits)) { if ((*num1)->sign == (*num2)->sign) { (*result)->sign = 0; while (List_sub(&(*num1)->digits, &(*num2)->digits, &(*result)->digits->val) >= 0) { count = count + 1; (*num1)->digits = List_sub(&(*num1)->digits, &(*num2)->digits, &(*result)->digits); } count = count - 1; } else if ((*num1)->sign != (*num2)->sign) { (*result)->sign = 1; while (List_sub(&(*num1)->digits, &(*num2)->digits, &(*result)->digits->val) >= 0) { count = count + 1; (*num1)->digits = List_sub(&(*num1)->digits, &(*num2)->digits, &(*result)->digits); } count = count - 1; } } else if ((List_size((*num2)->digits) == 1) && ((*num2)->digits->val == 0 )) printf ("Division by zero\n"); else { (*result)->sign = 0; (*result)->digits = 0; } return; }
//中缀转换为后缀表达式 void MiddleToHou(const vector<stExpStackValue>& middle, vector<stExpStackValue>& hou) { stack<stExpStackValue> temp_stack; //主要存储临时值 for(size_t i = 0 ; i < middle.size();) { if(middle[i].type == Expr_Fun) {//函数 temp_stack.push(middle[i]);//将函数入临时栈 } else if(middle[i].type == Expr_OP) { if(middle[i].op_value == OP_LEFT_B) {//左括号 if(!temp_stack.empty() && temp_stack.top().type == Expr_Fun) {//如果前一个是函数 //生成一个逗号放入hou 表示一个函数的开始,在计算后缀表达式时 这个逗号将标志一个函数的结束 stExpStackValue comma; comma.type = Expr_OP; comma.op_value = OP_COMMA; hou.push_back(comma); } temp_stack.push(middle[i]); //左括号入临时栈 } else if(middle[i].op_value == OP_RIGHT_B) {//右括号 stExpStackValue temp = temp_stack.top(); while(!(temp.type == Expr_OP && temp.op_value == OP_LEFT_B)) { hou.push_back(temp); temp_stack.pop(); temp = temp_stack.top(); } temp_stack.pop(); // 把左括号弹出去 //左括号下面如果是函数 取出来放进hou if(!temp_stack.empty() && temp_stack.top().type == Expr_Fun) { hou.push_back(temp_stack.top()); temp_stack.pop(); } } else if(middle[i].op_value == OP_COMMA) {//逗号 while(temp_stack.top().type == Expr_OP) { if(temp_stack.top().op_value == OP_LEFT_B) {//遇见左括号 break; } hou.push_back(temp_stack.top()); temp_stack.pop(); } //逗号忽略掉 //hou.push_back(middle[i]); } else {//一般运算符 if(!temp_stack.empty() && temp_stack.top().type == Expr_OP) { if(Bigger(middle[i].op_value, temp_stack.top().op_value)) { temp_stack.push(middle[i]); } else { hou.push_back(temp_stack.top()); temp_stack.pop(); if(temp_stack.empty()) { temp_stack.push(middle[i]); } else { while(!temp_stack.empty()) { if(temp_stack.top().type == Expr_OP) { if(temp_stack.top().op_value != OP_LEFT_B) { if(Bigger(middle[i].op_value, temp_stack.top().op_value)) { temp_stack.push(middle[i]); break; } else { hou.push_back(temp_stack.top()); temp_stack.pop(); } } else { temp_stack.push(middle[i]); break; } } else break; } } } } else { temp_stack.push(middle[i]); } } } else {//是一个操作数 直接放入 后缀vector hou.push_back(middle[i]); } i++; } while(!temp_stack.empty()) { stExpStackValue temp = temp_stack.top(); hou.push_back(temp); temp_stack.pop(); } }
int main() { std::cout << Bigger(10, 'c'); }