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 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
28# include <iostream>
29# include <string>
30# include <htlist.H>
31# include <filter_iterator.H>
32
33using namespace std;
34
35using namespace Aleph;
36
37void print(HTList & l)
38{
39 cout << "l: ";
40 for (HTList::Iterator it(l); it.has_curr(); it.next())
41 {
42 Snodenc<int> * p = (Snodenc<int>*) it.get_curr();
43 cout << p->get_data() << " ";
44 }
45 cout << endl;
46}
47
48struct Par
49{
50 bool operator () (int i) const
51 {
52 return i % 2 == 0;
53 }
54};
55
57
58
59int main(int argc, char * argv[])
60{
61 int n = 10;
62 if (argc > 1)
63 {
64 try
65 {
66 n = stoi(argv[1]);
67 }
68 catch (...)
69 {
70 n = 10;
71 }
72 }
73
74 if (n <= 0)
75 {
76 cerr << "Error: n must be a positive integer." << endl;
77 return 1;
78 }
79
80 HTList list;
81
82 for (int i = 0; i < n; ++i)
83 list.append(new Snodenc<int>(i));
84
85 while (not list.is_empty())
86 delete list.remove_first();
87
88
89 for (int i = 0; i < n; ++i)
90 list.append(new Snodenc<int>(i));
91
92 HTList l1, l2;
93
94 size_t sz = list.split_list(l1, l2);
95
96 cout << "Lista de " << sz << " elementos partida en dos" << endl;
97 print(l1);
98 cout << endl;
99
100 print(l2);
101 cout << endl;
102
103 list.append(l2);
104 print(list);
105 list.insert(l1);
106
107 print(list);
108
109 list.reverse();
110 print(list);
111
112 HTList::Iterator it(list);
113 for (int i = 0; it.has_curr() and i < n/10; it.next(), ++i)
114 ;
115
116 list.cut(it.get_curr(), l1);
117
118 print(list);
119 cout << endl;
120
121 print(l1);
122 cout << endl;
123
126
127 cout << "****************" << endl;
128
129 DynList<int> l = {7};
130
131 for (int i = 0; i < n; ++i)
132 l.append(i);
133
134 DynList<int> ll = {2};
135
136 ll = l ;
137
138 cout << "Mostrando todos los elementos .. " << endl;
139 for (DynList<int>::Iterator it(ll); it.has_curr(); it.next())
140 cout << it.get_curr() << " " ;
141 cout << endl;
142
143 for (It it(ll); it.has_curr(); it.next())
144 cout << it.get_curr() << " " ;
145 cout << endl;
146
148
149 lll.reverse();
150
151 l.append(l);
152
153 l.append(ll);
154
156
158
159 print(l);
160}
Iterator on the items of list.
Definition htlist.H:1420
Dynamic singly linked list with functional programming support.
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.
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.
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.
bool operator()(int i) const
Definition test_htlist.C:50
DynList< int > l1
DynList< int > l2
void print(HTList &l)
Definition test_htlist.C:37
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It
Definition test_htlist.C:56
DynList< int > l