-
Notifications
You must be signed in to change notification settings - Fork 1
/
DiseaseList.cpp
124 lines (88 loc) · 2.24 KB
/
DiseaseList.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//Kanellaki Maria Anna - 1115201400060
#include "DiseaseList.h"
DiseaseNode::DiseaseNode(PatientRecord *rec) //initializes a DiseaseNode with given disease id
{
disease = rec->getDiseaseId();
for (int & age_stat : age_stats) //initializes array to 0s
age_stat = 0;
AddAgeToStats(rec->getAge()); //increases the age range where rec's age belongs
next = NULL;
}
DiseaseNode::~DiseaseNode() //deletes next's pointer, without deleting that element
{
next = NULL;
delete next;
}
void DiseaseNode::AddAgeToStats(int age) //increases counter of the age range where age belongs in
{
if (age <= 20)
age_stats[0]++;
else if (age <= 40)
age_stats[1]++;
else if (age <= 60)
age_stats[2]++;
else
age_stats[3]++;
}
DiseaseList::DiseaseList() //initializes empty list
{
head = NULL;
}
DiseaseList::~DiseaseList() //deletes whole list
{
DiseaseNode *curr, *temp = head;
while (temp)
{
curr = temp;
temp = temp->getNext();
delete curr;
}
}
void DiseaseList::push(DiseaseNode *dnode) //insertion at the beginning of the list for speed
{
if (SearchDisease(dnode->getDisease())) //ignores duplicate entries
return;
if (head)
dnode->setNext(head);
head = dnode;
}
DiseaseNode * DiseaseList::SearchDisease(string name)
{
DiseaseNode *dnode = head;
while (dnode)
{
if (dnode->getDisease() == name)
return dnode;
dnode = dnode->getNext();
}
delete dnode;
return NULL;
}
string DiseaseList::calculateTopkAges(int k, string disease)
{
DiseaseNode *temp = SearchDisease(disease);
string str;
if (!temp)
return nullptr;
return str;
}
//getters and setters for both classes
DiseaseNode *DiseaseNode::getNext() const
{
return next;
}
void DiseaseNode::setNext(DiseaseNode *next)
{
DiseaseNode::next = next;
}
string DiseaseNode::getDisease() const
{
return disease;
}
DiseaseNode *DiseaseList::getHead() const
{
return head;
}
int DiseaseNode::getAgeStats(int pos) {
return age_stats[pos];
}