Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testSlist.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 <tpl_slist.H>
30
31using namespace std;
32
33int main()
34{
35 Slist<int> list;
37
38 int i;
39
40 for (i = 0; i < 20; i++)
41 {
42 p = new Slist<int>::Node (i);
43 list.insert_first(p);
44 }
45
46 p = list.get_first();
47 do
48 {
49 cout << p->get_data() << " ";
50 p = p->get_next();
51 } while (p not_eq &list);
52
53 cout << endl;
54
55 for (Slist<int>::Iterator itor(list); itor.has_curr(); itor.next())
56 {
57 p = itor.get_curr();
58 cout << p->get_data() << " ";
59 }
60
61 try
62 {
63 while (1)
64 {
65 p = list.remove_first();
66 delete p;
67 }
68 }
69 catch (std::underflow_error)
70 {
71 cout << "List has been emptied"<< endl;
72 }
73}
74
75
76
Iterator over singly linked nodes.
Definition tpl_slist.H:174
bool has_curr() const noexcept
Return true if the iterator currently points to a node.
Definition tpl_slist.H:198
Singly linked list of nodes that store values of type T.
Definition tpl_slist.H:102
Snode< T > Node
Definition tpl_slist.H:106
Node * get_first()
Return a pointer to the first node; throw if the list is empty.
Definition tpl_slist.H:142
void insert_first(Node *node)
Insert node right after this sentinel (at the beginning).
Definition tpl_slist.H:115
Node * remove_first()
Remove the first node of the list.
Definition tpl_slist.H:134
Singly linked node that stores data of type T.
Definition tpl_snode.H:66
T & get_data()
Return a modifiable reference to the stored data.
Definition tpl_snode.H:73
Snode *& get_next()
Return the next node after this.
Definition tpl_snode.H:91
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.
int main()
Definition testSlist.C:33
Singly linked list with typed nodes.