-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpriority.cpp
More file actions
57 lines (44 loc) · 766 Bytes
/
priority.cpp
File metadata and controls
57 lines (44 loc) · 766 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
55
56
/*
* priority.cpp
*
*
* Created by Bobby's Macbook on 2/8/12.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "priority.h"
void PQType::Dequeue(nodeType& item)
{
item = heap.elements[0];
heap.elements[0] = heap.elements[numItems-1];
numItems--;
heap.ReheapDown(0, numItems-1);
}
void PQType::Enqueue(nodeType& newItem)
{
numItems++;
heap.elements[numItems-1] = newItem;
heap.ReheapUp(0, numItems-1);
}
PQType::PQType(int max)
{
maxItems = max;
heap.elements = new nodeType[max];
numItems = 0;
}
void PQType::MakeEmpty()
{
numItems = 0;
}
PQType::~PQType()
{
delete [ ] heap.elements;
}
bool PQType::IsFull() const
{
return numItems == maxItems;
}
bool PQType::IsEmpty() const
{
return numItems == 0;
}