c++排序sort、稳定排序stable_sort、逆序rever()#include <iostream>
#include <algorithm>
#include <functional>
bool greater_cmp(int a,int b);
手选bool less_cmp(int a,int b);
using namespace std;
int main()
{
int a[]={1,20,5,2,6,20};
int a_len = sizeof(a)/sizeof(int);
cout<<"原来的顺序:"<<endl;
for(int i=0;i<a_len;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"逆序"<<endl;
rever(a,a+a_len);
for(int i=0;i<a_len;i++)
{推荐信范文
cout<<a[i]<<" ";
}
ciba
cout<<endl;
cout<<"使⽤STL,降序排序"<<endl;
sort(a,a+a_len,greater<int>());
for(int i=0;i<a_len;i++)
{
gpb
空格键英文cout<<a[i]<<" ";
}
cout<<endl;
cout<<"使⽤STL升序排序"<<endl;
sort(a,a+a_len,less<int>());
for(int i=0;i<a_len;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"⾃定义函数降序排序"<<endl;
sort(a,a+a_len,greater_cmp);
devi
for(int i=0;i<a_len;i++)
{
cout<<a[i]<<" ";
榴莲的英文}
cout<<endl;
cout<<"使⽤⾃定义函数升序排序"<<endl; sort(a,a+a_len,less_cmp);
for(int i=0;i<a_len;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"稳定排序"<<endl;
stable_sort(a,a+a_len,less_cmp);
for(int i=0;i<a_len;i++)
{
cout<<a[i]<<" ";
encourage
}
cout<<endl;
在线少儿英语那家好}
devil什么意思bool greater_cmp(int a,int b){
return a>b;
}
bool less_cmp(int a,int b){
return a<b;
}
c语⾔的排序: