-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test1.cpp
70 lines (59 loc) · 1.48 KB
/
sort_test1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*************************************************************************
> File Name: sort_test1.cpp
> Author: Feng
> Created Time: Wed 21 Nov 2018 02:05:50 PM CST
> Content:
************************************************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Person
{
public:
string name;
unsigned int age;
unsigned int score;
};
bool mycmp(Person p1, Person p2)
{
return p1.age < p2.age;
}
bool mycmp2(Person p1, Person p2)
{
return (int)p1.age - (int)p1.score > (int)p2.age - (int)p2.score;
}
int main()
{
vector<Person> persons;
Person p1;
p1.name = "J";
p1.age = 1;
p1.score = 13;
Person p2;
p2.name = "K";
p2.age = 8;
p2.score = 9;
persons.push_back(p1);
persons.push_back(p2);
for (auto it = persons.begin(); it != persons.end(); ++it) {
cout << (*it).name << endl;
}
cout << "sort" << endl;
sort(persons.begin(), persons.end(), mycmp);
for (auto it = persons.begin(); it != persons.end(); ++it) {
cout << (*it).name << endl;
}
cout << "sort2" << endl;
sort(persons.begin(), persons.end(), mycmp2);
for (auto it = persons.begin(); it != persons.end(); ++it) {
cout << (*it).name << endl;
}
unsigned int a = 10;
unsigned int b = 20;
cout << (int)a - (int)b << endl;
cout << a - b << endl;
cout << (int)(a - b) << endl;
return 0;
}