-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscientistsort.cpp
59 lines (51 loc) · 1.52 KB
/
scientistsort.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
#include "scientistsort.h"
//Comparer function that sorts Scientists
bool ScientistSort::Comparer::operator()(const Scientist &a, const Scientist &b){
switch(field){
case FIRST_NAME:
if(order == ASC){
return a.firstName.compare(b.firstName) < 0;
} else {
return a.firstName.compare(b.firstName) > 0;
}
break;
case LAST_NAME:
if(order == ASC){
return a.lastName.compare(b.lastName) < 0;
} else {
return a.lastName.compare(b.lastName) > 0;
}
break;
case GENDER:
if(order == ASC){
return a.gender < b.gender;
} else {
return a.gender > b.gender;
}
break;
case BIRTH_DATE:
if(order == ASC){
return a.birthdate < b.birthdate;
} else {
return a.birthdate > b.birthdate;
}
break;
case DEATH_DATE:
if(order == ASC){
return a.deathdate < b.deathdate;
} else {
return a.deathdate > b.deathdate;
}
break;
case NATIONALITY:
if(order == ASC){
return a.nationality.compare(b.nationality) < 0;
} else {
return a.nationality.compare(b.nationality) > 0;
}
break;
default:
return true;
break;
}
}