This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cpp
92 lines (83 loc) · 1.7 KB
/
Queue.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by jimena on 3/25/17.
//
#include "Queue.h"
#include "powerUp.h"
template <typename T>
Queue<T>::Queue() {
head=NULL;
lenght=0;
}
template <typename T>
T Queue<T>::dequeue() {
Node<T>* temp = new Node<T>;
if(head==NULL){
cout<<"Empty Queue"<<endl;
}else{
temp = head;
head = head->next;
lenght--;
return temp->data;
}
}
template <typename T>
void Queue<T>::enqueue(T data) {
if(head == NULL){
head = new Node<T>;
head->data = data;
head->next = NULL;
}else{
Node<T>* temp = head;
Node<T>* newNode = new Node<T>;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = newNode;
newNode->data = data;
}
lenght ++;
}
template <typename T>
void Queue<T>::printQueue() {
cout<<"[";
if(head != NULL) {
Node<T> *temp = head;
while(temp != NULL){
cout<<temp->data.getType()<<",";
temp = temp->next;
}
}else{
cout << "EmptyQueue";
}
cout<<"]"<<endl;
}
template <typename T>
bool Queue<T>::isEmpty() {
bool result = false;
if(head ==NULL){
result = true;
}
return result;
}
template <typename T>
void Queue<T>::dequeueAll() {
for(int i=0; i<lenght; i++) {
Node<T> *temp = new Node<T>;
if (head == NULL) {
cout << "Empty Queue" << endl;
} else {
temp = head;
head = head->next;
}
}
lenght = 0;
}
template <typename T>
Node<T> *Queue<T>::getHead() const {
return head;
}
template <typename T>
int Queue<T>::getLenght() const {
return lenght;
}
template class Queue<powerUp>;