-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.cpp
135 lines (107 loc) · 3.44 KB
/
main.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//*****************************************************************************************************
//
// This program demonstrates the use of the Queue class by instantiating a singly linked list
// queue of short integers and performing its methods.
//
// Other files required:
// 1. queue.h - header file for the Queue class
//
//*****************************************************************************************************
#include "queue.h"
#include <iostream>
using namespace std;
//*****************************************************************************************************
void displayQueue(bool success, Queue<short> &shortQueue);
void checkState(Queue<short> &shortQueue);
//*****************************************************************************************************
int main() {
Queue<short> shortQueue;
short num;
bool success;
checkState(shortQueue);
for (int i = 0; i < 10; ++i) {
num = 10 * (i + 1);
success = shortQueue.enqueue(num);
if (success)
cout << "enqueued: " << num << endl;
displayQueue(success, shortQueue);
}
cout << endl;
for (int i = 0; i < 10; ++i) {
success = shortQueue.dequeue(num);
if (success)
cout << "dequeued: " << num << endl;
displayQueue(success, shortQueue);
}
return 0;
}
//*****************************************************************************************************
void displayQueue(bool success, Queue<short> &shortQueue) {
short front,
back;
int numVal;
if (success) {
numVal = shortQueue.getNumValues();
shortQueue.viewFront(front);
shortQueue.viewRear(back);
if (numVal > 0)
cout << "numValues: " << numVal
<< "\tfront: " << front
<< "\tback: " << back << endl;
else
cout << "numValues: " << numVal << endl;
}
checkState(shortQueue);
}
//*****************************************************************************************************
void checkState(Queue<short> &shortQueue) {
if (shortQueue.isFull())
cerr << "\nqueue is full\n\n";
else if (shortQueue.isEmpty())
cerr << "\nqueue is empty\n\n";
}
//*****************************************************************************************************
/*
queue is empty
enqueued: 10
numValues: 1 front: 10 back: 10
enqueued: 20
numValues: 2 front: 10 back: 20
enqueued: 30
numValues: 3 front: 10 back: 30
enqueued: 40
numValues: 4 front: 10 back: 40
enqueued: 50
numValues: 5 front: 10 back: 50
enqueued: 60
numValues: 6 front: 10 back: 60
enqueued: 70
numValues: 7 front: 10 back: 70
enqueued: 80
numValues: 8 front: 10 back: 80
enqueued: 90
numValues: 9 front: 10 back: 90
enqueued: 100
numValues: 10 front: 10 back: 100
dequeued: 10
numValues: 9 front: 20 back: 100
dequeued: 20
numValues: 8 front: 30 back: 100
dequeued: 30
numValues: 7 front: 40 back: 100
dequeued: 40
numValues: 6 front: 50 back: 100
dequeued: 50
numValues: 5 front: 60 back: 100
dequeued: 60
numValues: 4 front: 70 back: 100
dequeued: 70
numValues: 3 front: 80 back: 100
dequeued: 80
numValues: 2 front: 90 back: 100
dequeued: 90
numValues: 1 front: 100 back: 100
dequeued: 100
numValues: 0
queue is empty
*/