c++中sort函数是一种可以简易排序的方式。
1.首先,其必要的头文件格式如下:
#include<algorithm>
using namespacce std:
2.其效果是将给定区间的元素进行默认升序的排列,时间复杂度为n*log2(n),相较于我们最先接触的冒泡排序更为有效率。
3.
示例:
#include<iostream>
#Include<algorithm>
using namespace std:
int main()
{
int A[9]={55,22,66,77,11,33,88,44,99};
for(int x=0;x<9;x++)
cout<<A[x]<<endl;
sort(A,A+9);
for(int x=0;x<9;x++)
cout<<A[x]<<endl;
return 0;
}
输出为:
55 22 66 77 11 33 88 44 99
11 22 33 44 55 66 77 88 99