Repository navigation
Expand file tree
/
Copy pathPriorityQueueApp.hpp
More file actions
65 lines (53 loc) · 2.22 KB
/
Copy pathPriorityQueueApp.hpp
File metadata and controls
65 lines (53 loc) · 2.22 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
#ifndef PriorityQueueApp_hpp
#define PriorityQueueApp_hpp
#include "PriorityQueue.hpp"
#include <iostream>
using namespace std;
namespace Demo {
class PriorityQueueApp {
public:
static void run() {
cout << "\n===Priority Queue===" << endl;
struct Patient{
int value;
string name;
int priority;
};
Patient patient;
cout << "Enter the maximum number of patients: ";
int maxPatients;
cin >> maxPatients;
if (maxPatients <= 0) {
cout << "Invalid maximum number of patients. Exiting." << endl;
return;
}
PriorityQueue<Patient> pq(maxPatients);
cout << "Example of inserting into the priority queue" << endl;
for (int i = 0; i < maxPatients; i++) {
cout << "Enter the name of the Patient and Priority: " << endl;
cin >> patient.name >> patient.priority;
patient = {i + 1, patient.name, patient.priority};
if (pq.insert(patient)) {
cout << "Patient " << patient.name << " with priority " << patient.priority << " added successfully." << endl;
} else {
cout << "Failed to add patient. Priority Queue is full." << endl;
}
}
Patient patient_max;
if (pq.getMax(patient_max)) {
cout << "The patient with the maximum priority is: " << patient_max.name << " with priority " << patient_max.priority << endl;
} else {
cout << "The priority queue is empty" << endl;
}
cout << "The number of patients in the priority queue: " << pq.getCount() << endl;
cout << "\nExample of removing from the priority queue:" << endl;
Patient removedPatient;
while (pq.getMax(removedPatient)) {
cout << "Removed patient: " << removedPatient.name << " with priority " << removedPatient.priority << endl;
}
cout << "No more patients to remove." << endl;
cout << "===Priority Queue Complete===" << endl;
}
};
}
#endif