-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriorityqueue.h
More file actions
80 lines (66 loc) · 1.55 KB
/
Copy pathpriorityqueue.h
File metadata and controls
80 lines (66 loc) · 1.55 KB
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
77
78
79
80
#ifndef priorityqueue_H
#define priorityqueue_H
#include <iostream>
#include <map>
using namespace std;
typedef float Priority;
template< typename Item>
class priorityqueue: public multimap<Priority, Item>
{
public:
multimap<Priority, Item> M;
priorityqueue() {}
Item& front()
{
auto it = M.begin();
for(auto its = M.begin(); its != M.end(); its++)
{
if(it->first > its->first)
{
it = its;
}
}
return it->second;
}
void pop()
{
if(M.empty())
{
return;
}
auto it = M.begin();
for(auto its = M.begin(); its != M.end(); its++)
{
if(it->first > its->first)
{
it = its;
}
}
M.erase(it);
}
void push(Item x, Priority p) // can you have multiple values in same priority?
{
//doing this as if cant and will overwrite the thing at same priority
M.insert(M.end(), pair<Priority,Item>(p,x));
}
priorityqueue<Item>(const priorityqueue<Item>& X)
{
this->M = X.M;
}
priorityqueue<Item>& operator = (const priorityqueue<Item> &PRIORITY_QUEUE)
{
priorityqueue<Item>* NEW = new priorityqueue<Item>;
NEW->M = PRIORITY_QUEUE.M;
this->M = NEW->M;
return *NEW;
}
bool empty() //made for testing
{
if(M.empty())
{
return true;
}
return false;
}
};
#endif