-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
56 lines (45 loc) · 1.21 KB
/
queue.cpp
File metadata and controls
56 lines (45 loc) · 1.21 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
//Provide the implementation for the Queue class in this file.
#include <iostream>
using namespace std;
template <class T>
Queue<T>::Queue(LinearStructure<T>* c) : OrderedContainer<T>(c){}
template <class T>
Queue<T>::Queue(const Queue<T>& other) : OrderedContainer<T>(other){}
template <class T>
Queue<T>& Queue<T>::operator=(const Queue<T>& other){
this->dataStructure = other.dataStructure->clone();
return *this;
}
template <class T>
Queue<T>::~Queue(){
this->dataStructure->clear();
}
template <class T>
T Queue<T>::remove(){
T result = this->dataStructure->remove(this->dataStructure->getIndexFirst());
return result;
}
template <class T>
T Queue<T>::next(){
T result = this->dataStructure->get(this->dataStructure->getIndexFirst());
return result;
}
template <class T>
void Queue<T>::insert(T el){
if(this->dataStructure->isEmpty()){
this->dataStructure->insert(0, el);
}
else{
this->dataStructure->insert(this->dataStructure->getIndexLast() + 1, el);
}
}
template <class T>
void Queue<T>::reverse(){
int i = 0;
LinearStructure<T> * temp = this->dataStructure->clone();
this->dataStructure->clear();
while(!temp->isEmpty()){
this->dataStructure->insert(i, temp->remove(temp->getIndexLast()));
i++;
}
}