-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOPriorityQueue.cpp
More file actions
55 lines (44 loc) · 946 Bytes
/
OPriorityQueue.cpp
File metadata and controls
55 lines (44 loc) · 946 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by Stepan Dergachev on 07.07.18.
//
#include "OPriorityQueue.h"
OPriorityQueue::OPriorityQueue() : IOpenContainer()
{
Pq = std::priority_queue<Node, std::vector<Node>, bool(*)(const Node&, const Node&)>(compare);
}
OPriorityQueue::OPriorityQueue(bool breakingties) : IOpenContainer(breakingties)
{
if(this->breakingties)
{
compare = &gMaxComparePQ;
}
else
{
compare = &gMinComparePQ;
}
Pq = std::priority_queue<Node, std::vector<Node>, bool(*)(const Node&, const Node&)>(compare);
}
OPriorityQueue::OPriorityQueue(OPriorityQueue const &a) : IOpenContainer(a)
{
this->Pq = a.Pq;
}
OPriorityQueue::~OPriorityQueue()
{
while(Pq.size())
{
Pq.pop();
}
}
void OPriorityQueue::Add(Node elem)
{
Pq.push(elem);
size += 1;
return;
}
Node OPriorityQueue::GetOptimal()
{
Node result = Pq.top();
Pq.pop();
size -= 1;
return result;
}