-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestsList.cpp
75 lines (56 loc) · 1.81 KB
/
requestsList.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
71
72
73
74
75
#include "requestsList.h"
/* Adding an item to the beginning of the list (pushing to the list) */
void RequestListPush(RequestNode ** head, Date requestsDate, string countryName){
RequestNode * new_node = new(RequestNode);
/* Update data */
new_node->requestsDate = requestsDate;
new_node->country = countryName;
new_node->next = *head;
new_node->requestsCounter++;
/* Now the new RequestNode will be the list's head */
*head = new_node;
}
/* Counts no. of nodes in linked list */
int RequestListCount(RequestNode* head){
RequestNode* current = head;
int counter = 0;
while (current != NULL) {
current = current->next;
counter++;
}
return counter;
}
int RequestListCount(RequestNode * head, Date date1, Date date2){
int counter = 0;
RequestNode * current = head;
int i = 1;
while (current != NULL){
if (((current->requestsDate.compareDates(date1)) >= 0) && ((current->requestsDate.compareDates(date2)) <= 0)){
counter++;
}
current = current->next;
}
return counter;
}
int RequestListCount(RequestNode * head, string countryName, Date date1, Date date2){
int counter = 0;
RequestNode * current = head;
int i = 1;
while (current != NULL){
if (((current->requestsDate.compareDates(date1)) >= 0) && ((current->requestsDate.compareDates(date2)) <= 0)){
if (current->country.compare(countryName) == 0)
counter++;
}
current = current->next;
}
return counter;
}
void RequestListDelete(RequestNode** head){
RequestNode* current = *head; // Initialize current
RequestNode* temp = NULL;
while (current != NULL) {
temp = current;
current = current->next;
delete temp;
}
}