-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementation2.cpp
More file actions
74 lines (63 loc) · 1.97 KB
/
Copy pathimplementation2.cpp
File metadata and controls
74 lines (63 loc) · 1.97 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
#include <iostream>
#include <queue>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
// Structure for Patient
struct Patient {
int id;
string name;
int severity; // Higher severity = Higher priority
int waitingTime;
};
// Structure for Doctor
struct Doctor {
int id;
string name;
int availableSlots;
};
// Priority Queue Comparator for Patient
struct ComparePatient {
bool operator()(const Patient &p1, const Patient &p2) {
return (p1.severity + p1.waitingTime) < (p2.severity + p2.waitingTime);
}
};
// Function to match patients with doctors
void matchPatientsToDoctors(priority_queue<Patient, vector<Patient>, ComparePatient> &patientQueue,
vector<Doctor> &doctors) {
unordered_map<int, vector<int>> doctorPatientMap; // Doctor ID -> Patient IDs
for (auto &doctor : doctors) {
while (!patientQueue.empty() && doctor.availableSlots > 0) {
Patient topPatient = patientQueue.top();
patientQueue.pop();
doctorPatientMap[doctor.id].push_back(topPatient.id);
doctor.availableSlots--;
}
}
// Display the scheduling results
cout << "\nScheduling Results:\n";
for (const auto &entry : doctorPatientMap) {
cout << "Doctor ID " << entry.first << " is assigned to Patients: ";
for (const auto &patientId : entry.second) {
cout << patientId << " ";
}
cout << endl;
}
}
int main() {
// Input: Patients
priority_queue<Patient, vector<Patient>, ComparePatient> patientQueue;
patientQueue.push({1, "John", 8, 2});
patientQueue.push({2, "Alice", 5, 3});
patientQueue.push({3, "Bob", 9, 1});
patientQueue.push({4, "Eve", 6, 2});
// Input: Doctors
vector<Doctor> doctors = {
{1, "Dr. Smith", 2},
{2, "Dr. Watson", 2}
};
// Perform Doctor-Patient Matching
matchPatientsToDoctors(patientQueue, doctors);
return 0;
}