-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparators.c
52 lines (40 loc) · 1.3 KB
/
comparators.c
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
#include "comparators.h"
#include "Record.h"
// Array of function pointers to all the available comparators.
int (*comparator[FIELD_NUM])(Record*, Record*)= {id_cmp,
name_cmp,
surname_cmp,
home_addr_cmp,
home_num_cmp,
city_cmp,
mail_cmp,
salary_cmp};
int id_cmp(Record* r1, Record* r2){
return ( r1->id - r2->id );
}
int name_cmp(Record* r1, Record* r2){
return strcmp(r1->name, r2->name);
}
int surname_cmp(Record* r1, Record* r2){
return strcmp(r1->surname, r2->surname);
}
int home_addr_cmp(Record* r1, Record* r2){
return strcmp(r1->home_address, r2->home_address);
}
int home_num_cmp(Record* r1, Record* r2){
return ( r1->home_number - r2->home_number );
}
int city_cmp(Record* r1, Record* r2){
return strcmp(r1->city, r2->city);
}
int mail_cmp(Record* r1, Record* r2){
return strcmp(r1->mail_sector, r2->mail_sector);
}
int salary_cmp(Record* r1, Record* r2){
return ( r1->salary - r2->salary );
}
void swap(Record** r1, Record** r2){
Record* temp = *r1;
*r1 = *r2;
*r2 = temp;
}