-
Notifications
You must be signed in to change notification settings - Fork 377
/
FCdemo.cpp
69 lines (66 loc) · 1.44 KB
/
FCdemo.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
#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <string>
#include <vector>
// -std=c++11
using namespace std;
//constant
class Person
{
public:
Person(string lastname, string firstname)
: _firstname(firstname), _lastname(lastname)
{
}
string firstname() const
{
return _firstname;
}
string lastname() const
{
return _lastname;
}
private:
const string _firstname = nullptr;
const string _lastname = nullptr;
};
class PersonSortCriterion
{
public:
bool operator()(const Person &p1, const Person &p2) const
{
return p1.lastname() < p2.lastname() ||
(p1.lastname() == p2.lastname() && p1.firstname() < p2.firstname());
}
};
class PersonSortCriterion1
{
public:
bool operator()(const Person &p1, const Person &p2) const
{
return p1.lastname() > p2.lastname() ||
(p1.lastname() == p2.lastname() && p1.firstname() > p2.firstname());
}
};
int main(void)
{
set<Person, PersonSortCriterion1> coll;
//unordered_set<Person> coll;
Person p1("yu", "g");
Person p2("an", "yu");
Person p3("xiao", "ming");
Person p4("xi", "biaoge");
Person p5("u", "ong");
coll.insert(p1);
coll.insert(p2);
coll.insert(p3);
coll.insert(p4);
coll.insert(p5);
for (auto i : coll)
{
cout << i.lastname() << ", " << i.firstname() << endl;
}
return 0;
}