#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>//一般是可以把时间传进去当成一个随机种子
using namespace std;
// bool cmp(int a, int b){ //a是否应该排在b的前面
// return a < b; //如果a < b的话 a就应该排在b的前面
// }
struct Rec{
int x, y;
}a[5];
bool cmp(Rec a, Rec b){ //a是否应该排在b的前面
return a.x < b.x; //如果a < b的话 a就应该排在b的前面
}
int main(){
//int a[] = {1, 1, 2, 2, 3, 4};
vector<int> a({1, 2, 3, 4, 5});
srand(time(0));//random_shuffle会用到随机种子 这个随机种子默认是0;
random_shuffle(a.begin(), a.end());//左闭右开
for(int x : a) cout << x << ' ';
cout << endl;
sort(a.begin(), a.end(), greater<int>());//加greater<int>()参数就可以变成从大到小排序
sort(a.begin(), a.end(), cmp);
for(int x : a) cout << x << ' ';
cout << endl;
//自己定义结构体的话是否也能排序呢
for(int i = 0; i < 5; i++){
a[i].x = -i;
a[i].y = i;
}
for(int i = 0; i < 5; i++) printf("(%d, %d)", a[i].x, a[i].y);
cout << endl;
sort(a, a + 5, cmp);
for(int i = 0; i < 5; i++) printf("(%d, %d)", a[i].x, a[i].y);
cout << endl;
// sort(a, a + 5);//因为结构体是没有比较函数的所以会报错
sort
return 0;
}