Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test_htlist.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
33# include <iostream>
34# include <string>
35# include <htlist.H>
36# include <filter_iterator.H>
37
38using namespace std;
39
40using namespace Aleph;
41
42void print(HTList & l)
43{
44 cout << "l: ";
45 for (HTList::Iterator it(l); it.has_curr(); it.next())
46 {
47 Snodenc<int> * p = (Snodenc<int>*) it.get_curr();
48 cout << p->get_data() << " ";
49 }
50 cout << endl;
51}
52
53struct Par
54{
55 bool operator () (int i) const
56 {
57 return i % 2 == 0;
58 }
59};
60
62
63
64int main(int argc, char * argv[])
65{
66 int n = 10;
67 if (argc > 1)
68 {
69 try
70 {
71 n = stoi(argv[1]);
72 }
73 catch (...)
74 {
75 n = 10;
76 }
77 }
78
79 if (n <= 0)
80 {
81 cerr << "Error: n must be a positive integer." << endl;
82 return 1;
83 }
84
85 HTList list;
86
87 for (int i = 0; i < n; ++i)
88 list.append(new Snodenc<int>(i));
89
90 while (not list.is_empty())
91 delete list.remove_first();
92
93
94 for (int i = 0; i < n; ++i)
95 list.append(new Snodenc<int>(i));
96
97 HTList l1, l2;
98
99 size_t sz = list.split_list(l1, l2);
100
101 cout << "Lista de " << sz << " elementos partida en dos" << endl;
102 print(l1);
103 cout << endl;
104
105 print(l2);
106 cout << endl;
107
108 list.append(l2);
109 print(list);
110 list.insert(l1);
111
112 print(list);
113
114 list.reverse();
115 print(list);
116
117 HTList::Iterator it(list);
118 for (int i = 0; it.has_curr() and i < n/10; it.next(), ++i)
119 ;
120
121 list.cut(it.get_curr(), l1);
122
123 print(list);
124 cout << endl;
125
126 print(l1);
127 cout << endl;
128
131
132 cout << "****************" << endl;
133
134 DynList<int> l = {7};
135
136 for (int i = 0; i < n; ++i)
137 l.append(i);
138
139 DynList<int> ll = {2};
140
141 ll = l ;
142
143 cout << "Mostrando todos los elementos .. " << endl;
144 for (DynList<int>::Iterator it(ll); it.has_curr(); it.next())
145 cout << it.get_curr() << " " ;
146 cout << endl;
147
148 for (It it(ll); it.has_curr(); it.next())
149 cout << it.get_curr() << " " ;
150 cout << endl;
151
153
154 lll.reverse();
155
156 l.append(l);
157
158 l.append(ll);
159
161
163
164 print(l);
165}
int main()
Iterator on the items of list.
Definition htlist.H:1420
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1155
T & insert(const T &item)
Definition htlist.H:1220
T & append(const T &item)
Definition htlist.H:1271
DynList & reverse() noexcept
Definition htlist.H:1469
Generic filter iterator wrapper.
Slinknc * get_curr() const
Definition htlist.H:952
bool has_curr() const noexcept
Definition htlist.H:930
Single linked list of nodes.
Definition htlist.H:403
void remove_all_and_delete() noexcept
Definition htlist.H:847
size_t reverse() noexcept
It inverts all list elements. It returns list size.
Definition htlist.H:786
constexpr bool is_empty() const noexcept
Definition htlist.H:419
void cut(Slinknc *link, HTList &list) noexcept
It cuts 'this' over 'link' element and it puts all.
Definition htlist.H:820
void append(Slinknc *link) noexcept
Definition htlist.H:495
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying.
Definition htlist.H:731
Slinknc * remove_first()
Definition htlist.H:641
void insert(Slinknc *link) noexcept
Definition htlist.H:473
T & get_data() noexcept
Return a modifiable reference to the data.
Definition htlist.H:287
Generic filter iterator wrapper for Aleph containers.
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.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
STL namespace.
bool operator()(int i) const
Definition test_htlist.C:55
DynList< int > l1
DynList< int > l2
void print(HTList &l)
Definition test_htlist.C:42
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It
Definition test_htlist.C:61
DynList< int > l