47template <
template <
typename T>
class List,
52 for (
int i = 0; i < n; ++i)
58template <
template <
typename T>
class List,
62 T value = numeric_limits<T>::min();
63 return list.all([&
value] (
const T & item)
65 bool ret =
value <= item;
71template <
template <
typename T>
class List,
76 for (
int i = 0; i < n; ++i)
82template <
template <
typename T>
class List,
86 T value = numeric_limits<T>::min();
87 return list.all([&
value] (
T * ptr)
89 bool ret =
value <= *ptr;
95template <
template <
typename T>
class List,
typename T>
98 list.for_each([] (
T * ptr)
104int main(
int argc,
char *argv[])
106 unsigned long n = 1000;
110 char * endptr =
nullptr;
111 const unsigned long parsed = strtoul(argv[1], &endptr, 10);
112 if (errno != 0 or endptr == argv[1] or *endptr !=
'\0' or
113 parsed >
static_cast<unsigned long>(INT_MAX))
115 cerr <<
"Invalid n: must be a non-negative integer <= "
122 unsigned int t = std::time(NULL);
126 char * endptr =
nullptr;
127 const unsigned long parsed_t = strtoul(argv[2], &endptr, 10);
128 if (errno != 0 or endptr == argv[2] or *endptr !=
'\0' or
131 cerr <<
"Invalid t: " << argv[2] << endl;
134 t =
static_cast<unsigned int>(parsed_t);
137 cout << argv[0] <<
" " << n <<
" " << t << endl;
142 cout <<
"Testing quicksort on single lists" << endl
143 <<
"Building list ... " << endl;
145 cout <<
"sorting it ..." << endl;
147 cout <<
"done! " << endl
148 <<
"Verifying ... " << endl;
151 cout <<
"done!" << endl
156 cout <<
"Testing quicksort on single lists of pointers" << endl
157 <<
"Building list ... " << endl;
159 cout <<
"sorting it ..." << endl;
164 cout <<
"done! " << endl
165 <<
"Verifying ... " << endl;
168 cout <<
"done!" << endl
174 cout <<
"Testing mergesort on single lists" << endl
175 <<
"Building list ... " << endl;
177 cout <<
"sorting it ..." << endl;
179 cout <<
"done! " << endl
180 <<
"Verifying ... " << endl;
183 cout <<
"done!" << endl
188 cout <<
"Testing mergesort on single lists of pointers" << endl
189 <<
"Building list ... " << endl;
191 cout <<
"sorting it ..." << endl;
196 cout <<
"done! " << endl
197 <<
"Verifying ... " << endl;
200 cout <<
"done!" << endl
206 cout <<
"Testing default sort method on single lists" << endl
207 <<
"Building list ... " << endl;
209 cout <<
"sorting it ..." << endl;
210 auto sorted =
sort(
l);
211 cout <<
"done! " << endl
212 <<
"Verifying ... " << endl;
214 assert(sorted.length() == n);
215 cout <<
"done!" << endl
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
High-level sorting functions for Aleph containers.
size_t size_t int32_t value
void append(Dlink *node) noexcept
Insert node before this.
Node belonging to a double circular linked list with header node.
Doubly-linked list (defined in tpl_dynList.H).
A random number generator with the sequences of GSL's gsl_rng_mt19937.
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
void seed(const unsigned long s) noexcept
Seeds again, as gsl_rng_set(r, s).
unsigned long get() noexcept
The next number, as operator()().
size_t length() const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< Container, T >)
Count the number of elements of a container.
std::decay_t< typename HeadC::Item_Type > T
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
void quicksort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using iterative quicksort with optimizations.
void mergesort(T *a, const long l, const long r, Array< T > &buf, Compare cmp)
Sort an array using merge sort with a reusable buffer.
List< T > build_int_list(int n)
List< T * > build_ptr_list(int n)
void free_ptr_list(List< T * > &list)
bool verify_sort(const List< T > &list)
Comprehensive sorting algorithms and search utilities for Aleph-w.