Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testDynListQueue.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27# include <ctime>
28# include <cstdlib>
29# include <cassert>
30
31# include <iostream>
32# include <string>
33# include <aleph.H>
34# include <tpl_dynListQueue.H>
35
36using namespace std;
37
38using namespace Aleph;
39
40# define NumItems 1000
41
42int main(int argc, char *argv[])
43{
44 int n = NumItems;
45 if (argc > 1)
46 {
47 try
48 {
49 n = stoi(argv[1]);
50 }
51 catch (...)
52 {
53 n = NumItems;
54 }
55 }
56
57 if (n <= 0)
58 {
59 cerr << "Error: n must be a positive integer." << endl;
60 return 1;
61 }
62
63 unsigned int t = std::time(0);
64
65 if (argc > 2)
66 {
67 try
68 {
69 t = stoi(argv[2]);
70 }
71 catch (...)
72 {
73 t = std::time(0);
74 }
75 }
76
77 srand(t);
78
79 cout << argv[0] << " " << n << " " << t << endl;
80
82
83 for (int i = 0; i < n; i++)
84 {
85 q.put(i);
86 cout << q.rear() << " ";
87 }
88
89 cout << endl;
90
91 while (not q.is_empty())
92 {
93 cout << q.front() << " ";
94 q.get();
95 }
96
97 cout << endl;
98}
Core header for the Aleph-w library.
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
T & front()
Return a modifiable reference to the oldest item in the queue.
T & rear()
Return a modifiable reference to the youngest item in the queue.
bool is_empty() const noexcept
Return true if this is empty.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
STL namespace.
#define NumItems
Dynamic queue implementation based on linked lists.