关于Tpoint 是平面点的坐标.ply是数组.定义如下

structTPoint
{
doublex,y;
}ply[N];

bool cmpx(TPoint a,TPoint b){return a.x<b.x;} 
sort(ply,ply+n,cmpx); 求这两个函数分别的作用.特别是bool cmpx函数究竟是怎么运作的???
如果能帮我将上面的bool cmpx函数改写成 类似以下代码 的形式,问题应该就解决了~~~
麻烦众大神解救~

int 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(a,a+n,cmp);
//是先按x升序排序,若x值相等则按y升序排

哈士奇WWW
浏览 117回答 1
1回答

弑天下

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;elseif( a.x == b.x ){if( a.y < b.y )return 1;elsereturn 0;}elsereturn 0;}sort(ply,ply+n,cmpx);我也是随便写的,你看一下吧。
打开App,查看更多内容
随时随地看视频慕课网APP