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 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33# include <iostream>
34# include <tpl_dnode.H>
35
36using namespace std;
37
39
40static long counter = 0;
41
43{
44 Node * head = new Node;
45 for (auto i = 0; i < n; ++i)
46 head->append(new Node(counter++));
47
48 return head;
49}
50
52{
53 Node * p = new Node(1000 + counter++);
54 for (auto i = 1; i < n; ++i)
55 p->append(new Node(1000 + counter++));
56 return p;
57}
58
59Node * access(Node * list, size_t n)
60{
61 Node::Iterator it(list);
62 for (auto i = 0; i < n; ++i)
63 it.next();
64 return it.get_curr();
65}
66
67ostream & operator << (ostream & out, Node * p)
68{
69 for (Node::Iterator it(p); it.has_curr(); it.next())
70 out << it.get_curr()->get_data() << " ";
71 return out;
72}
73
74
75int main(int argc, char *argv[])
76{
77 if (argc != 4)
78 {
79 cout << "usage: " << argv[0] << " n m i" << endl
80 << endl
81 << "Where n: number of items of big list" << endl
82 << " m: number of items of sublist to be inserted" << endl
83 << " i: position where the sublist will be inserted" << endl;
84 exit(0);
85 }
86
87 size_t n = atoi(argv[1]);
88 size_t m = atoi(argv[2]);
89 size_t i = atoi(argv[3]);
90
91 Node * list = create_list_with_header(n);
92
93 access(list, i)->splice(create_list_without_header(m));
94
95 cout << list << endl;
96
97 list->remove_all_and_delete();
98 delete list;
99}
WeightedDigraph::Node Node
int main()
size_t size_t int32_t * out
Definition ca-c-api.h:120
Node belonging to a double circular linked list with header node.
Definition tpl_dnode.H:106
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
Definition ahDefs.C:125
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:42
static long counter
Definition test-splice.C:40
Node * create_list_without_header(size_t n)
Definition test-splice.C:51
Node * access(Node *list, size_t n)
Definition test-splice.C:59
Dnode< long > Node
Definition test-splice.C:38
Doubly linked list node with typed data.