排序

1.代码实现

 1 #include<iostream>
 2 #include<algorithm>
 3 //sort所需要的头文件 
 4 using namespace std;
 5 int main()
 6 {
 7    int a[10]={9,6,3,8,5,2,7,4,1,0};
 8    cout<<"The old:"<<endl;
 9    for(int i=0;i<10;i++)
10    cout<<a[i]<<" ";
11    cout<<endl; 
12    sort(a,a+10);
13    //对数组a进行排序 
14    cout<<"The new:"<<endl;
15    for(int i=0;i<10;i++)
16    cout<<a[i]<<" ";
17    return 0;
18 }

2.运行结果

The old:
9 6 3 8 5 2 7 4 1 0
The new:
0 1 2 3 4 5 6 7 8 9
--------------------------------
Process exited after 0.9063 seconds with return value 0
请按任意键继续. . .
原文地址:https://www.cnblogs.com/2016024291-/p/6679793.html