-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueuePriority.cpp
More file actions
47 lines (33 loc) · 811 Bytes
/
QueuePriority.cpp
File metadata and controls
47 lines (33 loc) · 811 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
#include "QueuePriority.h"
QueuePriority::QueuePriority(map < char, int > x)
{
map<char, int>::iterator i = x.begin();
Albero = new ARB(i->second); i++;
while(i!=x.end()) {
Insert(i->second);
i++;
}
}
bool QueuePriority::Insert(const int i)
{
Nodo* x = new Nodo(i, Albero->GetNIL(),Albero->GetNIL(),Albero->GetNIL(),RED);
if (x->GetKey()<1)
{cout<<"IMPOSSIBILE INSERIRE ELEMENTO CON CHIAVE MINORE DI 1"<<endl; return 0;}
Albero->ins(x);
return 1;
}
int QueuePriority::Extract_MIN()
{
Nodo* tmp = Albero->GetMin(Albero->GetRoot());
int x = tmp->GetKey();
Albero->canc(tmp);
delete tmp;
return x;
}
int QueuePriority::Extract_MAX()
{
Nodo* tmp = Albero->GetMax(Albero->GetRoot());
int x = tmp->GetKey();
Albero->canc(tmp);
return x;
}