-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
49 lines (44 loc) · 970 Bytes
/
queue.cpp
File metadata and controls
49 lines (44 loc) · 970 Bytes
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
#include "atomic_queue.h"
#include <iostream>
int
main(int argc, char** argv)
{
std::vector<int> v;
Queue<int> q(20);
int cnt = 0;
std::cout << "Pointer queue" << std::endl;
v.resize(10);
for (int l = 0; l < 4; l++)
{
for (size_t i = 0; i < v.size(); i++)
{
v[i] = cnt++;
if (q.push(&v[i]) == false)
{
std::cerr << "not pushed." << std::endl;
}
}
while (int* v = q.pop())
{
std::cout << *v << std::endl;
}
std::cout << (q.empty() ? "EMPTY" : "-") << std::endl;
}
std::cout << "Number queue" << std::endl;
NQueue<int> nq{10, -1};
for (int l = 0; l < 4; l++)
{
for (int i = 0; i < 10; i++)
{
auto n = l * 10 + i;
if (nq.push(n) == false)
std::cout << "failed push: " << n << std::endl;
}
while (auto r = nq.pop())
{
std::cout << r.value << std::endl;
}
}
std::cout << "done." << std::endl;
return 0;
}