Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testMerge.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 <cstdio>
34# include <tpl_sort_utils.H>
35
36
37# define NumItems 200
38
40
41void printList(List & list)
42{
43 printf("\n");
44
45 List::Iterator itor(list);
46 Dnode<unsigned>* node;
47
48 for (itor.reset_first(); itor.has_curr(); itor.next())
49 {
50 node = itor.get_curr();
51 printf("%u ", node->get_data());
52 }
53
54 printf("\n");
55}
56
57
59{
60 bool operator() (Dlink * l1, Dlink * l2) const
61 {
62 return static_cast<Dnode<unsigned>*>(l1)->get_data() <
63 static_cast<Dnode<unsigned>*>(l2)->get_data();
64 }
65};
66
67int main()
68{
69 printf("Starting ........\n\n");
70
71 List list1;
72 List list2;
73
74 Dnode<unsigned>* node;
75
76 unsigned long i;
77
78 for (i = 0; i < NumItems; i++)
79 {
80 node = new Dnode<unsigned>;
81 node->get_data() = i;
82 list1.insert(node);
83 printf("%lu ", i);
84 }
85
86 printf("\n");
87
88 for (i = 0; i < NumItems; i++)
89 {
90 node = new Dnode<unsigned>;
91 node->get_data() = i;
92 list2.append(node);
93 printf("%lu ", i);
94 }
95
96 List list3;
97
99
101 printList(list2);
102
104
105 printf("Lists apparently merged and sorted\n");
106
108
109 list3.remove_all_and_delete();
110
111 printf("Ending .... \n\n");
112}
113
114
Iterator on a list of Dnode objects.
Definition tpl_dnode.H:260
Node belonging to a double circular linked list with header node.
Definition tpl_dnode.H:106
T & get_data() noexcept
Return a modifiable reference to the data contained in the node.
Definition tpl_dnode.H:232
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 quicksort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using iterative quicksort with optimizations.
bool operator()(Dlink *l1, Dlink *l2) const
Definition testMerge.C:60
DynList< int > l1
DynList< int > l2
Dnode< unsigned > List
Definition testMerge.C:39
void printList(List &list)
Definition testMerge.C:41
#define NumItems
Definition testMerge.C:37
int main()
Definition testMerge.C:67
Comprehensive sorting algorithms and search utilities for Aleph-w.