-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOVctProirityQueue.cpp
80 lines (64 loc) · 1.49 KB
/
OVctProirityQueue.cpp
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
//
// Created by Stepan Dergachev on 08.07.18.
//
#include "OVctProirityQueue.h"
OVctProirityQueue::OVctProirityQueue() : IOpenContainer()
{
vpqminindex = 0;
VctPq.resize(0);
}
OVctProirityQueue::OVctProirityQueue(bool breakingties, int mapheight) : IOpenContainer(breakingties)
{
vpqminindex = 0;
if(this->breakingties)
{
this->compare = &gMaxComparePQ;
}
else
{
this->compare = &gMinComparePQ;
}
VctPq.resize(mapheight);
for(int i = 0; i < VctPq.size(); i++)
{
VctPq[i]= std::priority_queue<Node, std::vector<Node>, bool(*)(const Node&, const Node&)>(compare);
}
}
OVctProirityQueue::OVctProirityQueue(OVctProirityQueue const &a) : IOpenContainer(a)
{
this->vpqminindex = a.vpqminindex;
this->VctPq = a.VctPq;
}
OVctProirityQueue::~OVctProirityQueue()
{
for(auto it = VctPq.begin(); it != VctPq.end(); ++it)
{
while(it->size())
{
it->pop();
}
}
}
void OVctProirityQueue::Add(Node elem)
{
VctPq[elem.i].push(elem);
size += 1;
return;
}
Node OVctProirityQueue::GetOptimal()
{
Node currOpt;
for (int i = 0; i < VctPq.size(); i++)
{
if (VctPq[i].size() && !this->compare(VctPq[i].top(), currOpt))
{
vpqminindex = i;
currOpt.F = VctPq[i].top().F;
currOpt.g = VctPq[i].top().g;
}
}
Node result = VctPq[vpqminindex].top();
VctPq[vpqminindex].pop();
size -= 1;
return result;
}