-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueue.h
More file actions
60 lines (45 loc) · 1.28 KB
/
PriorityQueue.h
File metadata and controls
60 lines (45 loc) · 1.28 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
// PriorityQueue.h - Header file for priority queue and related exceptions
#ifndef PRIORITYQUEUE_H
#define PRIORITYQUEUE_H
#include "Heap.h"
// FullPQ exception class definition
class FullPQ : public std::exception {
public:
FullPQ(const std::string& message = "Priority Queue is Full") : msg(message) {}
virtual const char* what() const throw() {
return msg.c_str();
}
private:
std::string msg;
};
// EmptyPQ exception class definition
class EmptyPQ : public std::exception {
public:
EmptyPQ(const std::string& message = "Priority Queue is Empty") : msg(message) {}
virtual const char* what() const throw() {
return msg.c_str();
}
private:
std::string msg;
};
// Priority Queue class definition
class PriorityQueue {
public:
PriorityQueue();
PriorityQueue(int max);
PriorityQueue(const PriorityQueue& other);
PriorityQueue& operator=(const PriorityQueue& other);
void enqueue(Order newItem);
void dequeue(Order& item);
void makeEmpty() { length = 0; }
bool isEmpty() const { return length == 0; }
bool isFull() const { return length == maxItems; }
int getLength() const { return length; }
int getMaxItems() const { return maxItems; }
private:
Heap items;
int length; // Keeps track of number of orders
int maxItems;
void copyQueue(const PriorityQueue& other);
};
#endif