-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheap.h
50 lines (42 loc) · 807 Bytes
/
heap.h
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
#pragma once
#include <vector>
#include <algorithm>
struct compare {
template<typename T>
bool operator()(const T& item1, const T& item2) const {
return item1 > item2;
}
};
template<class T>
class heap {
private:
std::vector<T> heap;
public:
void push(T value);
void pop();
bool empty();
size_t size();
T& front();
};
template<class T>
void heap<T>::push(T value){
heap.push_back(value);
std::push_heap(heap.begin(),heap.end(), compare());
}
template<class T>
void heap<T>::pop(){
std::pop_heap(heap.begin(),heap.end(), compare());
heap.pop_back();
}
template<class T>
bool heap<T>::empty(){
return heap.empty();
}
template<class T>
size_t heap<T>::size(){
return heap.size();
}
template<class T>
T& heap<T>::front(){
return heap.front();
}