-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTQueue.cpp
50 lines (45 loc) · 819 Bytes
/
TQueue.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
#include "TQueue.h"
TQueue::TQueue(int _size) {
head = 0;
tail = 0;
counter = 0;
size = _size;
arr = new int[size];
}
TQueue::~TQueue() {
delete[] arr;
}
TQueue::TQueue(const TQueue& Q) {
head = Q.head;
tail = Q.tail;
counter = Q.counter;
size = Q.size;
arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = Q.arr[i];
}
}
bool TQueue::Empty() {
return (counter == 0);
}
bool TQueue::Full() {
return (counter == size);
}
int TQueue::Get() {
int res = 0;
if (!Empty()) {
res = arr[head++];
if (head == size) head = 0;
counter--;
}
else cout << "Îøèáêà: î÷åðåäü ïóñòà!" << endl;
return res;
}
void TQueue::Put(int k) {
if (!Full()) {
if (tail == size) tail = 0;
arr[tail++] = k;
counter++;
}
else cout << "Î÷åðåäü ïåðåïîëíåíà. Ýëåìåíò íå ìîæåò áûòü äîáàâëåí." << endl;
}