-
Notifications
You must be signed in to change notification settings - Fork 1
/
DateList.cpp
122 lines (89 loc) · 2.18 KB
/
DateList.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
//Maria Anna Kanellaki - 1115201400060
#include "DateList.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
DateNode::DateNode(PatientRecord *rec) //initializes a DateNode with given Date
{
record = rec;
if (record->getEntryDate())
date = record->getEntryDate();
else
date = record->getExitDate();
myDiseases = new DiseaseList(); //initializes its disease list
myDiseases->push(new DiseaseNode(rec)); //and pushes the 1st element
next = NULL;
}
DateNode::~DateNode() //deletes next's pointer, without deleting that element
{
//delete date; //deleted by patient list
delete myDiseases;
next = NULL;
record = NULL;
delete next;
}
DateList::DateList() //initializes empty list
{
head = NULL;
}
DateList::~DateList() //deletes whole list
{
DateNode *curr, *temp = head;
while (temp)
{
curr = temp;
temp = temp->getNext();
delete curr;
}
}
DateNode* DateList::SearchDate(string d) //searches for a DateNode with date = given d
{
DateNode *dat = head;
while (dat)
{
if (dat->getDate()->getAsString() == d)
return dat;
dat = dat->getNext();
}
delete dat;
return NULL;
}
void DateList::push(DateNode *dat) //insertion at the beginning of the list for speed
{
DateNode *temp;
if ((temp = SearchDate(dat->getDate()->getAsString()))) //ignores duplicate dates
{
temp->getMyDiseases()->push(new DiseaseNode(dat->getRecord())); //insert new disease in my diseases list
return;
}
delete temp;
if (head)
dat->setNext(head);
head = dat;
}
//getters and setters for both classes
DateNode *DateNode::getNext() const
{
return next;
}
void DateNode::setNext(DateNode *next)
{
DateNode::next = next;
}
Date *DateNode::getDate() const
{
return date;
}
PatientRecord *DateNode::getRecord() const
{
return record;
}
DiseaseList *DateNode::getMyDiseases()
{
return myDiseases;
}
DateNode *DateList::getHead()
{
return head;
}