-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueList.h
101 lines (76 loc) · 1.29 KB
/
QueueList.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
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
93
94
95
96
97
98
99
100
101
#pragma once
class Queue
{
DoublyLinkedList list;
int max_count;
public:
Queue(int max_count)
{
this->max_count = max_count;
}
~Queue()
{
list.Clear();
}
void Clear()
{
list.Clear();
}
bool IsEmpty()
{
return list.GetCount() == 0;
}
bool IsFull()
{
return list.GetCount() == max_count;
}
int GetCount()
{
return list.GetCount();
}
void Enqueue(int number)
{
if (!IsFull())
{
list.AddToTail(number);
}
//else
// throw "OOPS! Queue is full!\n";
}
int Dequeue()
{
if (!IsEmpty())
{
int first = list.GetElementByIndex(0);
list.DeleteFromHead();
list.AddToTail(first);
return first;
}
else throw "Queue is empty!";
}
void Print()
{
// list.Print(); // !!! ïðåäïî÷òèòåëüíåå â ïëàíå îïòèìèçàöèè!
cout << "-----------------------------------------------------\n";
int x = list.GetCount();
for (int i = 0; i < x; i++)
cout << list.GetElementByIndex(i) << " ";
cout << "\n";
cout << "-----------------------------------------------------\n";
}
};
/*
// code for main:
Queue q(25);
for (int i = 0; i < 5; i++)
q.Enqueue(rand() % 90 + 10);
q.Print();
q.Dequeue();
q.Print();
for (int i = 0; i < 2; i++)
q.Enqueue(rand() % 90 + 10);
q.Print();
for (int i = 0; i < 3; i++)
q.Dequeue();
q.Print();
*/