-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority_queue.hh
35 lines (28 loc) · 907 Bytes
/
priority_queue.hh
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
#include "../../sort/include/sort"
#include <stdexcept>
#include <iterator>
template <class T>
struct ForwardIterator : std::iterator<std::forward_iterator_tag, T> {};
// Implementation of priority queue using max heap
template <class T>
class PriorityQueue {
std::vector<T> arr;
public:
PriorityQueue();
PriorityQueue(ForwardIterator<T> start, ForwardIterator<T> end);
// Increases value at index `i` to new value `key`
// i - index of value we want to increase
// key - new value, should be > or == to old value by index `i`
// Complexity: O(log(n))
void increase_key(int i, T key);
// Insert new value into queue
// x - new value to be inserted
// Complexity O(log(n))
void insert(T x);
// Pop value from the top of the queue
// Complexity O(log(n))
T pop();
// Peek the max value
// Complexity O(1)
T top();
};