//sort排序用法
//函数原型: void sort(iterator begin, iterator end);
//将[begin,end) 之间的元素使用默认的<进行排序
#include <algorithm> // 包含头文件
//自定义排序函数
bool cmp(const int a,const int b)
{ return a > b;}
int main()
{
int a[5]={3,4,1,2,5};
sort(a,a+5,cmp); //cmp,降序排序 5,4,3,2,1
sort(a,a+5); //默认升序排序,1,2,3,4,5
return 0;
}
//sort,自定义数据结构
#include <iostream>
#include <algorithm>
using namespace std;
struct Node
{
int x;
int y;
bool operator < (const struct Node& a) //重载<号
{
return x < a.x; //按x升序
//return x >a.x; //按x降序
}
}node[10];
int main()
{
node[0].x