-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbbst.cpp
More file actions
357 lines (317 loc) · 14.2 KB
/
bbst.cpp
File metadata and controls
357 lines (317 loc) · 14.2 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#include "bbst.h"
//GIA TO DENTRO
BBST::BBST(){
date = NULL;
list_of_records = NULL;
left_child = NULL;
right_child = NULL;
}
//constructor basei eggrafhs
BBST::BBST(record * rec){
date = new std::string(rec->get_entryDate());
list_of_records = new reclist(rec);
left_child = NULL;
right_child = NULL;
}
//SHMANTIKO. DIABASE TA SXOLIA MOY SE AUTON TON DESTRUCTOR
BBST::~BBST(){
delete date; //apodesmeush tou xwrou gia to string poy eixame
delete list_of_records; //svhnei th lista me idio tropo giati kathe komvos ths exei destructor
delete left_child; //Ean gia ena antikeimeno exei oristei destructor, H DELETE THA TON KALESEI
delete right_child; //auto shmainei oti kathe paidi tha kalei tautoxrona tous destructors twn paidiwn tou kai olo to dentro apodesmeuetai epituxws
//h eggrafh tha apodesmeutei apo th domh moy (aplos HT) opoy kai anhkei
}
//eisagei eggrafh sto dentro. den exoume data duplication afou milame gia deikth sthn arxikh eggrafh poy brisketai sth dikh moy domh aplou HT
int BBST::insert_record(record* rec){
//std::cout << dates_compare(rec->get_entryDate() , *date);
if(dates_compare(rec->get_entryDate() , *date) == "equal"){ //ean h hmeromhnia ths eggrafhs einai ish me tou komvou
//std::cout << "brhka idio date";
list_of_records->insert_record(rec); //valth sth lista tou komvou
return 0;
}//telos if gia hmeromhnia
else if(dates_compare(rec->get_entryDate() , *date) == "bigger"){ //ean h hmeromhnia ths eggrafhs einai megaluterh ap tou komvou
if(right_child == NULL){ //prepei na pame deksia kai den yparxei deksi paidi. to ftiaxnoume k paei ekei
right_child = new BBST(rec);
return 0;
}
else //yparxei deksi paidi, eksetazoume apo kei kai ustera
right_child->insert_record(rec);
}//telos else if gia hmeromhnia
else{ //hmeromhnia eggrafhs mikroterh tou komvou
if(left_child == NULL){ //prepei na pame aristera kai den yparxei deksi paidi. to ftiaxnoume k paei ekei
left_child = new BBST(rec);
return 0;
}
else //yparxei aristero paidi, eksetazoume apo kei kai ustera
left_child->insert_record(rec);
}//telos else gia hmeromhnia
}//telos sunarthshs
//arwgos sunarthsh
void BBST::collect_dated_reclists(BBST* root,std::string date2, search_containter * sc ){
if(root == NULL)
return; //xtyphsame akrh
std::string resu = dates_compare(*(root->date), date2); //sugkrish hmeromhnias entrydate komvou me date2
if(resu == "smaller"){ //ean h hmeromhnia twn eggrafwn einai mikroterh ths date2
sc->insert_reclist(root->list_of_records);
collect_dated_reclists(root->left_child, date2, sc);
collect_dated_reclists(root->right_child, date2, sc);
}
else if(resu == "equal"){ //an einai iso, den exei nohma na paei deksia
sc->insert_reclist(root->list_of_records);
collect_dated_reclists(root->left_child, date2, sc);
}
else if(resu == "bigger"){
collect_dated_reclists(root->left_child, date2, sc);
}
return;
}
//arwgos sunarthsh gia discharge
void BBST::collect_all_reclists(BBST* root, search_containter * sc ){
if(root == NULL)
return; //xtyphsame akrh
sc->insert_reclist(root->list_of_records);
collect_all_reclists(root->left_child, sc);
collect_all_reclists(root->right_child, sc);
return;
}
//gemizei ton simple epikouriko ht gia to topk
void BBST::populate_simpleht(simple_cd_HT * htptr){
if(list_of_records == NULL)
return; //de tha exoun krousmata oute ta paidia an den exei o gonios
else{ //exoume krousmata
reclist * currptr = list_of_records;
htptr->insert_krousma(list_of_records->recptr);
currptr = list_of_records->next;
while(currptr!= NULL){ //gia na piasei ola ta krousmata
htptr->insert_krousma(currptr->recptr);
currptr = currptr->next;
}//telos while gia reclist
}//telos else an exoume krousmata
if(left_child != NULL)//yparxei aristeropaidi
left_child->populate_simpleht(htptr);
if(right_child != NULL) //yparxei deksi paidi
right_child->populate_simpleht(htptr);
return;
}//telos sunarthshs
//dikh moy bohthhtikh ektypwsh
void BBST::print_contents(){
std::cout << "eimai komvos dentrou, exw date: " << *date << "\n";
list_of_records->print_contents();
if(left_child != NULL)
left_child->print_contents();
if(right_child != NULL)
right_child->print_contents();
}
//komvos listas gia diplotypes hmeromhnies
reclist::reclist(){
recptr = NULL;
next = NULL;
}
reclist::reclist(record * rec){
//std::cout << "yparxww kai bazww " << rec->get_patientFirstName();
recptr = rec;
next = NULL;
}
//destructor. H DELETE STHN C++ KALEI TOUS DESTRUCTORS ARA ME THN KLHSH THS DELETE GIA NEXT PAEI SE OLH TH LISTA
reclist::~reclist(){
delete next;
}
//bazei eggrafh sth lista
int reclist::insert_record(record * rec){
reclist * currptr = this;
while(currptr->next != NULL) //paei sto teleutaio
currptr = currptr->next ;
currptr->next = new reclist(rec);
return 0;
}
void reclist::print_contents(){
std::cout << "\t eimai h lista ston komvo t dentrou kai exw ta: ";
reclist * currptr = this;
while(currptr != NULL){ //paei mexri to telos
std::cout << currptr->recptr->get_patientFirstName() << currptr->recptr->get_exitDate() << "# ";
currptr = currptr->next ;
}//telos while gia next
std::cout << "\n";
}
//GIA THN ARWGO KLASH DATE1 DATE2 ERWTHMATWN
search_containter::search_containter(){
index =0;
arr = NULL;
}
search_containter::search_containter(int maxsize){
index =0;
arr = new reclist *[maxsize]{NULL}; //arxika oloi oi deiktes null
}
search_containter::~search_containter(){
delete[] arr; //mono to desmeumeno xwro. To periexomeno twn deiktwn prepei na meinei athikto
}
void search_containter::insert_reclist(reclist * rl){
arr[index] = rl;
index++;
}
//O,TI EINAI MESA STON CONTAINER EINAI ENTRYDATE <= DATE2. KOITAZEI GIA EXITDATE > DATE1
int search_containter::count_exit_limit(std::string date1){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return num_approved;
reclist * currptr = arr[i];
while(currptr != NULL){
if(currptr->recptr->get_exitDate() == "-") //einai akoma mesa. ton theloyme
num_approved++;
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "bigger" ){
num_approved++; //exei exitdate megalutero tou date1, to theloyme
}
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "equal" ){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" )
num_approved++; //vazei kai autous poy mphkan kai bghkan thn idia mera an to exitdate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return num_approved;
}//telos sunarthshs
//O,TI EINAI MESA STON CONTAINER EXEI ENTRYDATE <= DATE2. KOITAZEI GIA ENTRYDATE >= DATE1 TWRA
int search_containter::count_entry_limit(std::string date1){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return num_approved;
reclist * currptr = arr[i];
while(currptr != NULL){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "bigger" ){
num_approved++; //exei entry megalutero tou date1, to theloyme
}
else if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" ){
num_approved++; //vazei kai autous an to entrydate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return num_approved;
}//telos sunarthshs
//idia me apo panw aplws elegxei k country
int search_containter::count_entry_limit(std::string date1, std::string country){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return num_approved;
reclist * currptr = arr[i];
while(currptr != NULL){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "bigger" ){
if(currptr->recptr->get_country() == country) //tsekarw k country
num_approved++; //exei entry megalutero tou date1, to theloyme
}
else if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" ){
if(currptr->recptr->get_country() == country) //tsekarw k country
num_approved++; //vazei kai autous an to entrydate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return num_approved;
}//telos sunarthshs
//O,TI EINAI MESA STON CONTAINER EINAI ENTRYDATE <= DATE2. KOITAZEI GIA EXITDATE > DATE1 KAI EPIPLEON COUNTRY GIA THN DISEASEFREQUENCY
int search_containter::count_exit_limit(std::string date1, std::string country){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return num_approved;
reclist * currptr = arr[i];
while(currptr != NULL){
if((currptr->recptr->get_exitDate() == "-") && (currptr->recptr->get_country() == country)) //einai akoma mesa kai exei th xwra mas. ton theloyme
num_approved++;
else if((dates_compare(currptr->recptr->get_exitDate(), date1) == "bigger" )&& (currptr->recptr->get_country() == country)){ //koitame kai xwra pleon
num_approved++; //exei exitdate megalutero tou date1, to theloyme
}
else if((dates_compare(currptr->recptr->get_exitDate(), date1) == "equal" ) && (currptr->recptr->get_country() == country)){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" )
num_approved++; //vazei kai autous poy mphkan kai bghkan thn idia mera an to exitdate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return num_approved;
}//telos sunarthshs
int search_containter::count_exit_limit2(std::string date1, std::string date2, std::string country){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return num_approved;
reclist * currptr = arr[i];
while(currptr != NULL){
if((dates_compare(currptr->recptr->get_exitDate(), date1) == "bigger" )&& (currptr->recptr->get_country() == country)){ //koitame kai xwra pleon
if((dates_compare(currptr->recptr->get_exitDate(), date2) == "smaller" )||(dates_compare(currptr->recptr->get_exitDate(), date2) == "equal" ))
num_approved++; //exei exitdate megalutero tou date1, to theloyme
}
else if((dates_compare(currptr->recptr->get_exitDate(), date1) == "equal" ) && (currptr->recptr->get_country() == country)){
if((dates_compare(currptr->recptr->get_exitDate(), date2) == "smaller" )||(dates_compare(currptr->recptr->get_exitDate(), date2) == "equal" ))
num_approved++; //vazei kai autous poy mphkan kai bghkan thn idia mera an to exitdate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return num_approved;
}//telos sunarthshs
//disqualify tis exitdate <= date1 kai eisodos se simpleht gia topk
void search_containter::populate_simpleht(simple_cd_HT *htptr, std::string date1){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return;
reclist * currptr = arr[i];
while(currptr != NULL){
if(currptr->recptr->get_exitDate() == "-") //einai akoma mesa. ton theloyme
htptr->insert_krousma(currptr->recptr);
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "bigger" ){
htptr->insert_krousma(currptr->recptr); //exei exitdate megalutero tou date1, to theloyme
}
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "equal" ){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" )
htptr->insert_krousma(currptr->recptr); //vazei kai autous poy mphkan kai bghkan thn idia mera an to exitdate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return;
}
//disqualify tis exitdate <= date1 kai eisodos se simpleht gia topk MAZI ME ELEGXO DISEASE
void search_containter::populate_simpleht(simple_cd_HT *htptr, std::string date1, std::string disease_name){
int num_approved =0;
for(unsigned int i=0; i<index; i++){
if(arr[i] == NULL) //oi eisagwges ginontai h mia meta thn allh ksekinwntas apo to 0. to prwto null shmainei den exei alles
return;
reclist * currptr = arr[i];
while(currptr != NULL){
if(currptr->recptr->get_exitDate() == "-"){ //einai akoma mesa. ton theloyme
if(currptr->recptr->get_diseaseID() == disease_name) //MONO EAN EXEI TO DISEASE POY THELW THA ASXOLH8W
htptr->insert_krousma(currptr->recptr);
}
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "bigger" ){
if(currptr->recptr->get_diseaseID() == disease_name) //MONO EAN EXEI TO DISEASE POY THELW THA ASXOLH8W
htptr->insert_krousma(currptr->recptr); //exei exitdate megalutero tou date1, to theloyme
}
else if(dates_compare(currptr->recptr->get_exitDate(), date1) == "equal" ){
if(dates_compare(currptr->recptr->get_entryDate(), date1) == "equal" )
if(currptr->recptr->get_diseaseID() == disease_name) //MONO EAN EXEI TO DISEASE POY THELW THA ASXOLH8W
htptr->insert_krousma(currptr->recptr); //vazei kai autous poy mphkan kai bghkan thn idia mera an to exitdate einai iso me date1
}
else
num_approved += 0;
currptr = currptr->next;
}//telos while gia lista eggrafwn
}//telos for gia thn i lista
return;
}