sort()的用法

想用sort()函数需要加上   #include <algorethm>这个头文件;

sort(begin,end)表示一个范围;

如例子:


#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
int a[10]={1,8,7,6,9,4,3,5,2,10,},i;
for(i=0;i<10;i++)
cout<<a[i]<<endl;
sort(a,a+10);
for(i=0;i<10;i++)
cout<<a[i]<<endl;
return 0;
}

猜你喜欢

转载自www.cnblogs.com/phaLQ/p/9350308.html