Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testDynSlist.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 <aleph.H>
30# include <tpl_dynSlist.H>
31
32# define Num_Items 10
33
34using namespace std;
35
36int main()
37{
38 DynSlist<int> list;
39 DynSlist<int*> list_ptr;
40
41 for (int i = 0; i < Num_Items; i++)
42 {
43 list.insert(i, i);
44 list_ptr.insert(i, &i);
45 }
46
48
50
51 itor_aux = itor;
52
53 for (/* nothing */; itor.has_curr(); itor.next())
54 cout << itor.get_curr() << " ";
55
56 cout << endl;
57
58 for (int i = Num_Items; i < 2*Num_Items; i++)
59 list.insert(i - Num_Items, i);
60
61 for (itor.reset_first(); itor.has_curr(); itor.next())
62 cout << itor.get_curr() << " ";
63
64 cout << endl;
65
66 for (int i = 2*Num_Items; i < 3*Num_Items; i++)
67 list.insert(0, i);
68
69 for (itor.reset_first(); itor.has_curr(); itor.next())
70 cout << itor.get_curr() << " ";
71
72 cout << endl;
73
74 for (int i = 3*Num_Items; i < 4*Num_Items; i++)
75 list.insert(list.size(), i);
76
77 for (int i = 0; i < list.size(); i++)
78 cout << list[i] << " ";
79
80 cout << endl;
81
82 for (int i = 0; i < list.size(); i++)
83 cout << list[list.size() - i - 1] << " ";
84
85 cout << endl;
86
87 list.remove(list.size() - 1);
88
89 list.remove(0);
90
91 for (itor.reset_first(); itor.has_curr(); itor.next())
92 cout << itor.get_curr() << " ";
93
94 cout << endl;
95
96}
Core header for the Aleph-w library.
Iterator specialized for DynSlist returning payload references.
Dynamic list of elements of type T implemented with a singly linked list of nodes.
size_t size() const noexcept
Return the number of stored elements.
void remove(const int pos)
Remove the node at position pos.
void insert(const int pos, const T &data)
Insert an element at position pos.
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 Num_Items
int main()
Dynamic singly linked list.