-
Notifications
You must be signed in to change notification settings - Fork 0
/
CycleQueue.cpp
70 lines (61 loc) · 900 Bytes
/
CycleQueue.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
#include "CycleQueue.h"
#include <iostream>
CycleQueue::CycleQueue()
{
rear = 0;
front = 0;
}
CycleQueue::~CycleQueue()
{
}
int CycleQueue::IsEmpty()
{
return rear == front;
}
int CycleQueue::IsFull()
{
return (rear + 1) % MAX_QUEUE_LENGTH == front;
}
int CycleQueue::EnQueue(int x)
{
if (IsFull())
return false;
else
{
data[rear] = x;
rear = (rear + 1) % MAX_QUEUE_LENGTH;
return true;
}
}
void CycleQueue::Initialize()
{
rear = 0;
front = 0;
}
int CycleQueue::DeQueue(int &x)
{
if (IsEmpty())
return false;
else
{
x = data[front];
front = (front + 1) % MAX_QUEUE_LENGTH;
return true;
}
}
void CycleQueue::ShowData()
{
if (IsEmpty())
std::cout << "´Ë¶ÓÁÐΪ¿Õ";
else
{
int i=front;
while (i%MAX_QUEUE_LENGTH != rear)
{
std::cout << data[i%MAX_QUEUE_LENGTH] << " ";
i++;
}
if (IsFull()) std::cout << "¶ÓÁÐÒÑÂú";
}
std::cout << std::endl;
}