-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueList.cpp
66 lines (59 loc) · 1 KB
/
QueueList.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
#include "QueueList.h"
//C'tor
QueueList::QueueList()
{
head = NULL;
tail = NULL;
sizeQ = 0;
}
//Enqueue - add member to the queue
void QueueList::Enqueue(int value)
{
sizeQ++;
if (head == NULL)
{
Item* newItem = new Item(value, NULL, NULL);
tail = newItem;
head = newItem;
}
else
{
Item* newItem = new Item(value, tail, NULL);
tail->next = newItem;
tail = newItem;
}
}
//Dequeue - remove member from the queue
int QueueList::Dequeue()
{
int temp = head->value;
if (head->next != NULL)
{
head->next->prev = NULL;
head = head->next;
}
else
{
head = NULL;
tail = NULL;
}
return temp;
}
// IsEmpty - checking if the queue is empty
bool QueueList::IsEmpty()
{
bool res = false;
if (head == NULL && tail == NULL)
{
res = true;
cout << "The Q is empty" << endl;
return res;
}
else
return res;
}
//Top - return the next member which is supposed to come out
int QueueList::Top()
{
return head->value;
}