为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

哈士奇WWW 2022-11-18 18:14:46
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;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贡献1818条经验 获得超7个赞

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);
我也是随便写的,你看一下吧。

查看完整回答
反对 回复 2022-11-22
  • 1 回答
  • 0 关注
  • 63 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信