-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxHeap.h
More file actions
37 lines (29 loc) · 743 Bytes
/
MaxHeap.h
File metadata and controls
37 lines (29 loc) · 743 Bytes
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
#pragma once
#include <vector>
#include <string>
#include <stdexcept>
using namespace std;
struct Student {
string id;
int priority;
Student(string id, int priority)
: id(id), priority(priority) {}
};
class MaxHeap {
public:
MaxHeap();
void insert(const string& student, int priority);
void increase_key(string id, int new_priority);
Student extract_max();
Student get_max() const;
int size() const;
void remove(const string &id);
private:
vector<Student> data;
void heapify_up(int index);
void heapify_down(int index);
int parent(int index) const;
int left_child(int index) const;
int right_child(int index) const;
int find_student_index(string id) const;
};