-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriorityQueue.cpp
More file actions
60 lines (52 loc) · 1.29 KB
/
priorityQueue.cpp
File metadata and controls
60 lines (52 loc) · 1.29 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
//Provide the implementation for the PriorityQueue class in this file.
#include <iostream>
using namespace std;
template <class T>
PriorityQueue<T>::PriorityQueue(LinearStructure<T>* c) : Queue<T>(c){
max = true;
}
template <class T>
PriorityQueue<T>::PriorityQueue(const PriorityQueue<T>& other) : Queue<T>(other){
max = true;
}
template <class T>
PriorityQueue<T>& PriorityQueue<T>::operator=(const PriorityQueue<T>& other){
this->dataStructure = other.dataStructure->clone();
this->max = new bool(other.max);
return *this;
}
template <class T>
PriorityQueue<T>::~PriorityQueue(){
this->dataStructure->clear();
}
template <class T>
T PriorityQueue<T>::remove(){
if(max){
T result = this->dataStructure->remove(this->dataStructure->getIndexLast());
return result;
}
else{
T result = this->dataStructure->remove(this->dataStructure->getIndexFirst());
return result;
}
}
template <class T>
T PriorityQueue<T>::next(){
if(!max){
T result = this->dataStructure->get(this->dataStructure->getIndexLast());
return result;
}
else{
T result = this->dataStructure->get(this->dataStructure->getIndexFirst());
return result;
}
}
template <class T>
void PriorityQueue<T>::reverse(){
if(max){
max = false;
}
else{
max = true;
}
}