-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
90 lines (80 loc) · 1.61 KB
/
Copy pathqueue.cpp
File metadata and controls
90 lines (80 loc) · 1.61 KB
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
#include <iostream>
#include "queue.h"
Queue::Queue()
{
// initalize addition end and deletion end as -1 to signify an empty queue
front = -1;
end = -1;
}
void Queue::del()
{
int tmp;
if(front == -1)
{
std::cout << "QUEUE IS EMPTY!" << std::endl;
}
else
{
for(int x = 0; x <= end; x++)
{
// if the next item in the queue exists, move it forward
if((x+1) <= end)
{
tmp = t[x+1];
t[x] = tmp;
}
else
{
end--;
// if the beginning of the queue is not empty reset the end of the queue
if(end == -1)
{
front = -1;
}
else
{
front = 0;
}
}
}
}
}
void Queue::add(int item)
{
// if this is the first item increment front and end variables
// else increment end
if(end == -1 && front == -1)
{
front++;
end++;
t[end] = item;
}
else
{
end++;
// check if we have reached the maximum size, if alert the user
if(end == MAX)
{
std::cout << "QUEUE IS FULL!" << std::endl;
}
else
{
t[end] = item;
}
}
}
void Queue::display()
{
if(end != -1)
{
for(int x = 0; x <= end; x++)
{
std::cout << t[x] << " ";
}
std::cout << std::endl;
}
else
{
std::cout << "QUEUE IS EMPTY!" << std::endl;
}
}