Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testSlink.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 <aleph.H>
29# include <slink.H>
30
31# define NumItems 10
32
33struct Record1 : public Slink
34{
35 unsigned n;
36
37 Record1* get_next() { return static_cast<Record1*>(Slink::get_next()); }
38};
39
40struct Record2
41{
42 unsigned n;
43
45
47};
48# include <iostream>
49
50
51void* foo();
52
53int main()
54{
55 {
56 Record1 head;
57 unsigned i;
58 Record1 *node;
59 Record1 *aux;
60
61 for (i = 0; i < NumItems; i++)
62 {
63 node = new Record1;
64
65 node->n = i;
66 head.insert_next(node);
67 }
68
69 for (node = head.get_next(); node not_eq &head; node = node->get_next())
70 {
71 printf("%u ", node->n);
72 }
73
74 while (not head.is_empty())
75 {
76 aux = static_cast<Record1*>(head.remove_next());
77 delete aux;
78 }
79 }
80
81 {
82 Slink head;
83 unsigned i;
84 Record2 *node;
85 Slink *link;
86
87 for (i = 0; i < NumItems; i++)
88 {
89 node = new Record2;
90
91 node->n = i;
92 head.insert_next(&node->link);
93 }
94
95 for (link = head.get_next(); link not_eq &head; link = link->get_next())
96 {
97 node = Record2::slink_to_type(link);
98 printf("%u ", node->n);
99 }
100
101 while (not head.is_empty())
102 {
103 node = Record2::slink_to_type(head.remove_next());
104 delete node;
105 }
106 }
107
108 printf("Ended\n");
109}
Core header for the Aleph-w library.
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.
unsigned n
Definition testSlink.C:35
Record1 * get_next()
Definition testSlink.C:37
Slink link
Definition testSlink.C:44
unsigned n
Definition testSlink.C:42
static Record2 * slink_to_type(Slink *link)
Definition testSlink.C:46