-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExclusionProirityQueue.h
94 lines (79 loc) · 1.21 KB
/
ExclusionProirityQueue.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
class ExclusionPriorityQueue
{
int* ar;
int* pr;
int max_count;
int count;
public:
ExclusionPriorityQueue(int m)
{
max_count = m;
ar = new int[max_count];
pr = new int[max_count];
count = 0;
}
~ExclusionPriorityQueue()
{
delete[] ar;
delete[] pr;
}
void Clear()
{
count = 0;
}
bool IsEmpty()
{
return count == 0;
}
bool IsFull()
{
return count == max_count;
}
int GetCount()
{
return count;
}
void Enqueue(int number, int priority)
{
if (!IsFull())
{
ar[count] = number;
pr[count] = priority;
count++;
}
}
int Dequeue()
{
if (!IsEmpty())
{
int max_pr = pr[0];
int max_pr_position = 0;
for (int i = 1; i < count; i++)
{
if (max_pr < pr[i])
{
max_pr = pr[i];
max_pr_position = i;
}
}
int elem = ar[max_pr_position];
for (int i = max_pr_position; i < count - 1; i++)
{
ar[i] = ar[i + 1];
pr[i] = pr[i + 1];
}
count--;
return elem;
}
return -1;
}
void Print()
{
cout << "-----------------------------------------------------\n";
for (int i = 0; i < count; i++)
cout << ar[i] << " ";
cout << "\n";
cout << "-----------------------------------------------------\n";
}
};