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 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 <cstdio>
29# include <tpl_sort_utils.H>
30
31
32# define NumItems 200
33
35
36void printList(List & list)
37{
38 printf("\n");
39
40 List::Iterator itor(list);
41 Dnode<unsigned>* node;
42
43 for (itor.reset_first(); itor.has_curr(); itor.next())
44 {
45 node = itor.get_curr();
46 printf("%u ", node->get_data());
47 }
48
49 printf("\n");
50}
51
52
54{
55 bool operator() (Dlink * l1, Dlink * l2) const
56 {
57 return static_cast<Dnode<unsigned>*>(l1)->get_data() <
58 static_cast<Dnode<unsigned>*>(l2)->get_data();
59 }
60};
61
62int main()
63{
64 printf("Starting ........\n\n");
65
66 List list1;
67 List list2;
68
69 Dnode<unsigned>* node;
70
71 unsigned long i;
72
73 for (i = 0; i < NumItems; i++)
74 {
75 node = new Dnode<unsigned>;
76 node->get_data() = i;
77 list1.insert(node);
78 printf("%lu ", i);
79 }
80
81 printf("\n");
82
83 for (i = 0; i < NumItems; i++)
84 {
85 node = new Dnode<unsigned>;
86 node->get_data() = i;
87 list2.append(node);
88 printf("%lu ", i);
89 }
90
91 List list3;
92
94
96 printList(list2);
97
99
100 printf("Lists apparently merged and sorted\n");
101
103
104 list3.remove_all_and_delete();
105
106 printf("Ending .... \n\n");
107}
108
109
Iterator on a list of Dnode objects.
Definition tpl_dnode.H:261
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
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.
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:55
DynList< int > l1
DynList< int > l2
Dnode< unsigned > List
Definition testMerge.C:34
void printList(List &list)
Definition testMerge.C:36
#define NumItems
Definition testMerge.C:32
int main()
Definition testMerge.C:62
Comprehensive sorting algorithms and search utilities for Aleph-w.