-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatientPriorityQueue.h
More file actions
95 lines (79 loc) · 2.15 KB
/
Copy pathPatientPriorityQueue.h
File metadata and controls
95 lines (79 loc) · 2.15 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
//
// Created by Nichlos Ho on 10/30/20.
//
#ifndef PROJECT4_PATIENTPRIORITYQUEUE_H
#define PROJECT4_PATIENTPRIORITYQUEUE_H
#include <vector>
#include <algorithm>
#include "Patient.h"
/**
* This class holds a vector of patients in a min heap order.
*/
class PatientPriorityQueue {
public:
/**
* default zero arg constructor
*/
PatientPriorityQueue(); // zero-arg constructor
/**
* Adds patient to the back of the vector and will call percolateUp(int inedx) to heapify
* @param newItem patient object
*/
void enqueue(const Patient& newItem);
/**
* Removes the highest priority patient from the queue and returns it. It will then call percolateDown
* @return the patient removed
*/
Patient dequeue();
/**
* Returns the highest priority patient without removing it.
* @return root
*/
const Patient &peek() const;
/**
* Returns the number of patients still waiting.
* @return size
*/
int size();
/**
* retrieve the data of the patient such as name, priority code and order number.
* mainly used to toString patient details in main
* @param index of the vector
* @return patient at the index
*/
Patient getData(int index);
private:
/**
* vector of patients. Will be stored in a min heap order
*/
std::vector<Patient> data;
/**
* re-heapify upwards after a patient was added
* @param index
*/
void percolateUp(int index);
/**
* calculate the parent index of the child given in the parameter
* @param child
* @return parent index
*/
static int getParent(int child);
/**
* re-heapify downwards after a patient was removed
* @param index
*/
void percolateDown(int index);
/**
* calculate the right index of the parent given in the parameter
* @param index
* @return right index
*/
static int getRight(int index);
/**
* calculate the right index of the parent given in the parameter
* @param index
* @return left index
*/
static int getLeft(int index);
};
#endif //PROJECT4_PATIENTPRIORITYQUEUE_H