-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDoctorList.h
More file actions
211 lines (193 loc) · 5.04 KB
/
Copy pathDoctorList.h
File metadata and controls
211 lines (193 loc) · 5.04 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
// بسم الله الرحمن الرحيم
// "وَأَنْ لَيْسَ لِلْإِنسَانِ إِلَّا مَا سَعَىٰ"
// Free Palestine
#ifndef DOCTORLIST_H
#define DOCTORLIST_H
#include <bits/stdc++.h>
#include "PatientQueue.h"
#include "Doctor.h"
using namespace std;
class ListNode
{
public:
Doctor doctor; // Doctor object
PatientQueue Patients; // Queue of patients for this doctor
ListNode *next; // pointer to next node
ListNode(const Doctor &d) : doctor(d), next(nullptr) {}
};
class DoctorList
{
private:
ListNode *head;
ListNode *tail;
int DoctorsCount; // number of doctors
public:
DoctorList() : head(nullptr), tail(nullptr), DoctorsCount(0) {}
~DoctorList()
{
clear();
}
ListNode *getHead()
{
return head;
}
void addDoctor(const Doctor &doctor)
{
ListNode *newNode = new ListNode(doctor);
if (head == nullptr)
{
head = tail = newNode;
}
else
{
tail->next = newNode;
tail = newNode;
}
DoctorsCount++;
}
ListNode *SearchById(int DoctorId)
{
ListNode *curr = head;
while (curr != nullptr)
{
if (curr->doctor.getId() == DoctorId)
{
return curr; // return the whole doctor node
}
curr = curr->next;
}
return nullptr;
}
void deleteHead() // Support other delete methods (Omar Mohamed)
{
if (isEmpty())
{
return;
}
else if (DoctorsCount == 1)
{
delete head;
head = tail = nullptr;
DoctorsCount--;
}
else
{
ListNode *curr = head;
head = head->next;
delete curr;
DoctorsCount--;
}
}
Doctor deleteById(int DoctorId) // delete doctor from list with ID (Omar Mohamed)
{
if (isEmpty())
{
cout << "There Is No Doctors To Delete!" << nl;
return Doctor();
}
else
{
if (SearchById(DoctorId) == nullptr)
{
cout << "Invalid Id, Please Enter a Correct Doctor Id!\n";
return Doctor();
}
else
{
if (head->doctor.getId() == DoctorId)
{
Doctor temp = head->doctor;
deleteHead();
return temp;
}
else
{
ListNode *delNode = head;
ListNode *prev = head;
while (prev->next->doctor.getId() != DoctorId)
{
prev = prev->next;
}
Doctor temp = prev->next->doctor;
delNode = prev->next;
prev->next = delNode->next;
delete delNode;
DoctorsCount--;
return temp;
}
}
}
}
int doctorPatientCount(int DoctorId) // return the count of patients for a doctor that have this id (-MoRa-)
{
if (isEmpty())
{
cout << "Invalid Id, Please Enter a Correct Doctor Id!" << nl;
return 0;
}
else
{
if (SearchById(DoctorId) == nullptr)
{
cout << "Invalid Id, Please Enter a Correct Doctor Id!\n";
return 0;
}
else
{
if (head->doctor.getId() == DoctorId)
{
return head->Patients.getQueueCount();
}
else
{
ListNode *curr = head;
while (curr->doctor.getId() != DoctorId)
{
curr = curr->next;
}
return curr->Patients.getQueueCount();
}
}
}
}
void display() // This function display doctors queue
{
if (isEmpty())
{
cout << "There is no Doctors." << nl;
return;
}
else
{
ListNode *curr = head;
while (curr != nullptr)
{
cout << "Doctor ID : " << curr->doctor.getId() << "\n";
cout << "Name : " << curr->doctor.getName() << "\n";
cout << "Queue : " << curr->Patients.getQueueCount() << " waiting\n";
cout << "------------------------------------------\n";
curr = curr->next;
}
}
}
bool isEmpty() const
{
return head == nullptr;
}
int getCount() const
{
return DoctorsCount;
}
void clear()
{
while (head != nullptr)
{
ListNode *temp = head;
head = head->next;
delete temp;
}
tail = nullptr;
DoctorsCount = 0;
}
};
#endif