Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-splice.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_dnode.H>
30
31using namespace std;
32
34
35static long counter = 0;
36
38{
39 Node * head = new Node;
40 for (auto i = 0; i < n; ++i)
41 head->append(new Node(counter++));
42
43 return head;
44}
45
47{
48 Node * p = new Node(1000 + counter++);
49 for (auto i = 1; i < n; ++i)
50 p->append(new Node(1000 + counter++));
51 return p;
52}
53
54Node * access(Node * list, size_t n)
55{
56 Node::Iterator it(list);
57 for (auto i = 0; i < n; ++i)
58 it.next();
59 return it.get_curr();
60}
61
62ostream & operator << (ostream & out, Node * p)
63{
64 for (Node::Iterator it(p); it.has_curr(); it.next())
65 out << it.get_curr()->get_data() << " ";
66 return out;
67}
68
69
70int main(int argc, char *argv[])
71{
72 if (argc != 4)
73 {
74 cout << "usage: " << argv[0] << " n m i" << endl
75 << endl
76 << "Where n: number of items of big list" << endl
77 << " m: number of items of sublist to be inserted" << endl
78 << " i: position where the sublist will be inserted" << endl;
79 exit(0);
80 }
81
82 size_t n = atoi(argv[1]);
83 size_t m = atoi(argv[2]);
84 size_t i = atoi(argv[3]);
85
86 Node * list = create_list_with_header(n);
87
88 access(list, i)->splice(create_list_without_header(m));
89
90 cout << list << endl;
91
92 list->remove_all_and_delete();
93 delete list;
94}
WeightedDigraph::Node Node
Node belonging to a double circular linked list with header node.
Definition tpl_dnode.H:106
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
Definition ahDefs.C:132
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.
std::ostream & operator<<(std::ostream &osObject, const Field< T > &rightOp)
Definition ahField.H:121
STL namespace.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Node * create_list_with_header(size_t n)
Definition test-splice.C:37
static long counter
Definition test-splice.C:35
Node * create_list_without_header(size_t n)
Definition test-splice.C:46
Node * access(Node *list, size_t n)
Definition test-splice.C:54
Dnode< long > Node
Definition test-splice.C:33
Doubly linked list node with typed data.