-
Notifications
You must be signed in to change notification settings - Fork 0
/
VaccinationInfoList.cpp
86 lines (66 loc) · 2.33 KB
/
VaccinationInfoList.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
76
77
78
79
80
81
82
83
84
85
86
#include "VaccinationInfoList.h"
using namespace std;
void VInfoListPrint(VInfoNode * head){
VInfoNode * current = head;
cout << "Printing the list: " << endl;
int i = 1;
while (current != NULL) {
cout << i++ << ": " << current->vacInfo.virusName->virusName;
cout << " " << current->vacInfo.isVaccinated << " ";
if (current->vacInfo.dateVaccinated != NULL) /* If isVaccinated == "NO" => date == NULL => don't print it */
current->vacInfo.dateVaccinated->printDate();
cout << endl;
current = current->next;
}
cout << endl;
}
/* Adding an item to the beginning of the list (pushing to the list) */
void VInfoListPush(VInfoNode ** head, VaccinationInfo vacInfo){
VInfoNode * new_node = new VInfoNode;
/* Update data */
new_node->vacInfo = vacInfo;
new_node->next = *head;
/* Now the new VInfoNode will be the list's head */
*head = new_node;
}
/* Return "true" if "virusName" is in VirusInfo List or "false" if it isn't */
bool VInfoListSearch(VInfoNode* head, string virusName){
VInfoNode* current = head;
while (current != NULL){
if (current->vacInfo.virusName->virusName.compare(virusName) == 0)
return true;
current = current->next;
}
return false;
}
/* Return the address of VInfoNode if "virusName" is in VirusInfo List or NULL if it isn't */
VInfoNode* VInfoListSearch2(VInfoNode* head, string virusName){
VInfoNode* current = head;
while (current != NULL){
if (current->vacInfo.virusName->virusName.compare(virusName) == 0)
return current;
current = current->next;
}
return NULL;
}
int VInfoListCount(VInfoNode* head){
VInfoNode* current = head;
int counter = 0;
while (current != NULL) {
current = current->next;
counter++;
}
return counter;
}
void VInfoDeleteList(VInfoNode** head){
VInfoNode* current = *head;
VInfoNode* temp = NULL;
int i = 0;
while (current != NULL) {
temp = current;
current = current->next;
if (temp->vacInfo.dateVaccinated != NULL) /* Delete dates => only if they exist */
delete temp->vacInfo.dateVaccinated;
delete temp; /* Delete VInfoNode */
}
}