1 #include <iostream>
2 #include <algorithm>
3 using namespace std;
4 struct type_1
5 {
6 int a,b;
7 type_1(int x=0,int y=0):a(x),b(y){}
8 };
9 bool compare(type_1 a,type_1 b)
10 {
11 return a.a<b.a;
12 }
13 bool operator < (const type_1 &a,const type_1 &b)
14 {
15 return a.a<b.a;
16 }
17 ostream& operator<<(ostream &cout,const type_1 &a)
18 {
19 cout<<"("<<a.a<<","<<a.b<<")";
20 }
21 int main()
22 {
23 type_1 vec[10]={type_1(3,4),type_1(2,4),type_1(1,4),type_1(9,4),type_1(31,4),type_1(25,4),type_1(2,4),type_1(9,4),type_1(2,4),type_1(1,4)};
24 sort(vec,vec+10);//通过定义小于<
25 for(int i=0;i<10;i++)
26 cout<<vec[i]<<" ";
27 cout<<endl;
28
29 return 0;
30 }