Sort 函数的使用

sort函数的使用必须加上头文件“#include<algorithm>”和“using namespace std;”。

sort函数使用方法:sort(首元素地址,尾元素地址的下一个地址,比较函数);

其中,前两个是必填的,比价函数是非必填的,根据实际情况填写

#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a[6]={9,4,2,5,6,-1};
	sort(a,a+4);
	for(int i=0;i<6;i++){
		printf("%d ",a[i]);
	}
	return 0;
} 

Sort 函数的使用

 

上一篇:c# – 如何通过提供Windows.Media.FaceAnalysis DetectedFace列表使用Microsoft Cognitive服务检测面部属性?


下一篇:计算机网络面试题