-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.h
55 lines (46 loc) · 1 KB
/
Queue.h
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
#ifndef DATASTRUCTURE_QUEUE_H
#define DATASTRUCTURE_QUEUE_H
template<class T>
class Queue {
private:
int last;
int front;
T *arr;
int max_size;
public:
Queue(int max_size) {
this->max_size = max_size;
last = 0;
front = 0;
arr = new T[max_size];
}
~Queue() {
delete[] arr;
last = front = 0;
}
bool isFull() {
return (last + 1) % max_size == front;
}
bool isEmpty() {
return last == front;
}
void insert(T value) {
if (!isFull()) {
arr[last] = value;
last = (last + 1) % max_size;
} else {
cout << " \n the queue is full ! '" << value << "' didn't inserted! \n";
}
}
T delete_() {
if (!isEmpty()) {
T x = arr[front];
front = (front+1) % max_size;
return x;
} else {
cout << "queue is empty ! \n";
return NULL;
}
}
};
#endif //DATASTRUCTURE_QUEUE_H