1 #include<iostream>
2 #include<vector>
3 #include<algorithm>
4
5 using namespace std;
6 //二元谓词
7 class mycompare
8 {
9 public:
10 bool operator()(int val1, int val2)
11 {
12 return val1 > val2;
13 }
14 };
15
16 void test1()
17 {
18 vector<int> v;
19 v.push_back(10);
20 v.push_back(20);
21 v.push_back(30);
22 v.push_back(40);
23 v.push_back(50);
24
25 sort(v.begin(), v.end());
26 for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
27 {
28 cout << *it << " ";
29 }
30 cout << endl;
31 sort(v.begin(), v.end(),mycompare());
32 for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
33 {
34 cout << *it << " ";
35 }
36 }
37
38 int main()
39 {
40
41 test1();
42
43 return 0;
44 }