-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquetype.cpp
63 lines (62 loc) · 1.25 KB
/
quetype.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
#include "quetype.h"
template<class ItemType>
QueType<ItemType>::QueType(int max)
{
maxQue = max + 1;
front = maxQue - 1;
rear = maxQue - 1;
items = new ItemType[maxQue];
}
template<class ItemType>
QueType<ItemType>::QueType()
{
maxQue = 501;
front = maxQue - 1;
rear = maxQue - 1;
items = new ItemType[maxQue];
}
template<class ItemType>
QueType<ItemType>::~QueType()
{
delete [] items;
}
template<class ItemType>
void QueType<ItemType>::MakeEmpty()
{
front = maxQue - 1;
rear = maxQue - 1;
}
template<class ItemType>
bool QueType<ItemType>::IsEmpty()
{
return (rear == front);
}
template<class ItemType>
bool QueType<ItemType>::IsFull()
{
return ((rear+1)%maxQue == front);
}
template<class ItemType>
void QueType<ItemType>::Enqueue(ItemType
newItem)
{
if (IsFull())
throw FullQueue();
else
{
rear = (rear +1) % maxQue;
items[rear] = newItem;
}
}
template<class ItemType>
void QueType<ItemType>::Dequeue(ItemType&
item)
{
if (IsEmpty())
throw EmptyQueue();
else
{
front = (front + 1) % maxQue;
item = items[front];
}
}