关于sort中第三个参数的问题
  • 板块学术版
  • 楼主__凉皮__
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/4/30 20:41
  • 上次更新2023/10/28 02:33:15
查看原帖
关于sort中第三个参数的问题
259944
__凉皮__楼主2022/4/30 20:41
#include<bits/stdc++.h>
using namespace std;
int t[27];
bool cmp(int x,int y){
	return x>=y;
}
int main(){
    t[1]=5;
    t[4]=6;
    sort(t,t+27,cmp);
    for(int i=0;i<=6;i++)cout<<t[i]<<" ";
	system("pause");
	return 0;
}

当cmp中是x>y时,输出为:

6 5 0 0 0 0 0

当cmp中是x>=y时,输出为:

6421312 6 5 1 1 1 1

为什么会这样?

2022/4/30 20:41
加载中...