sort用法

代码
#include<iostream>
#include
<algorithm>
using namespace std;
int a[3000001];
/*
bool cmp(int a, int b)
{
return a>b; //a>b为从大到小,sort默认从小到大
}
*/
int main ()
{
int nCase,i;
while(scanf("%d", &nCase)+1)
{
int t=nCase;
while(t--) scanf("%d",&a[t]);
// sort(a,a+nCase,cmp); 此条需要cmp函数
sort(a,a+nCase);
for(i=0;i<nCase-1;i++) printf("%d ",a[i]);
printf(
"%d\n",a[i]);
}
return 0;
}
原文地址:https://www.cnblogs.com/submarinex/p/1941266.html