structTPoint{doublex,y;}ply[N];bool cmpx(TPoint a,TPoint b){return a.x<b.x;} sort(ply,ply+n,cmpx); 求這兩個(gè)函數(shù)分別的作用.特別是bool cmpx函數(shù)究竟是怎么運(yùn)作的???如果能幫我將上面的bool cmpx函數(shù)改寫(xiě)成 類(lèi)似以下代碼 的形式,問(wèn)題應(yīng)該就解決了~~~麻煩眾大神解救~int cmp( const POINT &a, const POINT &b ){if( a.x < b.x )return 1;elseif( a.x == b.x ){if( a.y < b.y )return 1;elsereturn 0;}elsereturn 0;}sort(a,a+n,cmp);//是先按x升序排序,若x值相等則按y升序排
1 回答

弒天下
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
bool cmpx(TPoint a,TPoint b){return a.x<b.x;}
意思是:
bool cmpx(TPoint a,TPoint b)
{if(a.x<b.x) return true;
else return false;}
下面改成:
bool cmp( const POINT &a, const POINT &b ){
if( a.x < b.x )
return 1;
else
if( a.x == b.x ){
if( a.y < b.y )
return 1;
else
return 0;
}
else
return 0;
}
sort(ply,ply+n,cmpx);
我也是隨便寫(xiě)的,你看一下吧。
添加回答
舉報(bào)
0/150
提交
取消