forked from HPI-Artificial-Intelligence-Teaching/24-pt2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.cpp
71 lines (58 loc) · 1.79 KB
/
queue.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
/******************************************************************************
*
* A generic queue using a fixed-size array.
*
* Based on the source code from Robert Sedgewick and Kevin Wayne at https://algs4.cs.princeton.edu/
*
* % ./queue
* Front of queue: 12
* Front of queue: 10
* Dequeued value: 10
* Dequeued value: 2
* is_empty (queue): 1
* Front of queue: This
* Front of queue: is
* Dequeued value: is
* Dequeued value: an
* Dequeued value: example
*
******************************************************************************/
#include "queue.h"
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
// test a queue of integers
void test_int_queue(void) {
Queue<int> q;
q.enqueue(12);
q.enqueue(10);
q.enqueue(2);
cout << setw(20) << "Front of queue: " << q.front() << endl;
q.dequeue();
cout << setw(20) << "Front of queue: " << q.front() << endl;
cout << setw(20) << "Dequeued value: " << q.dequeue() << endl;
cout << setw(20) << "Dequeued value: " << q.dequeue() << endl;
cout << setw(20) << "is_empty (queue): " << q.is_empty() << endl;
return;
}
// test a queue of strings
void test_string_queue(void) {
Queue<string> q;
q.enqueue("This");
q.enqueue("is");
q.enqueue("an");
q.enqueue("example");
cout << setw(20) << "Front of queue: " << q.front() << endl;
q.dequeue();
cout << setw(20) << "Front of queue: " << q.front() << endl;
cout << setw(20) << "Dequeued value: " << q.dequeue() << endl;
cout << setw(20) << "Dequeued value: " << q.dequeue() << endl;
cout << setw(20) << "Dequeued value: " << q.dequeue() << endl;
return;
}
int main(void) {
test_int_queue();
test_string_queue();
return (0);
}