Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testDynDlist.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 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32# include <ctime>
33# include <cstdlib>
34# include <cassert>
35
36# include <iostream>
37# include <string>
38
39# include <ahFunctional.H>
40# include <htlist.H>
41# include <tpl_dynDlist.H>
42
43using namespace std;
44
45
47{
48 for (DynDlist<int>::Iterator it(l); it.has_curr(); it.next())
49 cout << it.get_curr() << " ";
50
51 cout << "size = " << l.size() << " **" << endl;
52}
53
54
56{
57 int i = 0;
58 for (DynDlist<DynDlist<int> >::Iterator it(l); it.has_curr(); it.next())
59 {
60 cout << i++ << " : ";
61 imprime(it.get_curr());
62 cout << endl;
63 }
64}
65
66int main(int argc, char *argv[])
67{
68 int n = 1000;
69 if (argc > 1)
70 {
71 try
72 {
73 n = stoi(argv[1]);
74 }
75 catch (...)
76 {
77 n = 1000;
78 }
79 }
80
81 int m = 1000;
82 if (argc > 2)
83 {
84 try
85 {
86 m = stoi(argv[2]);
87 }
88 catch (...)
89 {
90 m = 1000;
91 }
92 }
93
94 // Validate inputs
95 if (n <= 0 or m <= 0)
96 {
97 cerr << "Error: n and m must be positive integers." << endl;
98 return 1;
99 }
100
101 unsigned int t = std::time(0);
102
103 if (argc > 3)
104 {
105 try
106 {
107 t = stoi(argv[3]);
108 }
109 catch (...)
110 {
111 t = std::time(0);
112 }
113 }
114
115 srand(t);
116
117 cout << argv[0] << " " << n << " " << m << " " << t << endl;
118
120 int i;
121
122 for (i = 0; i < n; i++)
123 {
125
126 for (int k = 0; k < m; ++k)
127 l.append(k);
128 }
129
130 imprime(list);
131
132 // Guard against empty list before calling get_first()
133 if (list.is_empty())
134 {
135 cerr << "Error: List is empty, cannot get first element." << endl;
136 return 1;
137 }
138
139 // DynDlist<int> te ( DynDlist<int>(list.get_first()) );
141
142 te = DynDlist<int>(list.get_first());
143
144 for (DynDlist<int>::Iterator it(te); it.has_curr(); it.next())
145 cout << it.get_curr() << endl;
146
147 // imprime(list);
148
149 {
150 DynDlist<int> l1 = range(10);
151 // DynDlist<int> l2 = range(10, 20);
152 l1.append(range(10, 20));
153 // expected output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
154 l1.for_each([] (auto i) { cout << i << " "; }); cout << endl;
155 // assert(l2.is_empty() and l2.size() == 0);
156 int i = 0;
157 assert(l1.all([&i] (auto k) { return k == i++; }));
158 }
159
160}
161
Functional programming utilities for Aleph-w containers.
int main()
Iterator dynamic list.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & get_first() const
Return a modifiable reference to first item in the list.
T & insert(const T &item)
Insert a copy of item at the beginning of the list.
T & append(const T &item)
Definition htlist.H:1271
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1065
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:796
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Definition ah-dry.H:984
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Singly linked list implementations with head-tail access.
Container< T > range(const T start, const T end, const T step=1)
Generate a range of values [start, end] with a given step.
STL namespace.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
DynList< int > l1
void imprime(DynDlist< int > &l)
static int * k
Dynamic doubly linked list implementation.
DynList< int > l