ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
SelectionSort.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*-------------------------- File SelectionSort.h --------------------------*/
3
/*--------------------------------------------------------------------------*/
23
/*--------------------------------------------------------------------------*/
24
/*----------------------------- DEFINITIONS --------------------------------*/
25
/*--------------------------------------------------------------------------*/
26
27
#ifndef __ADS_SelectionSort
28
#define __ADS_SelectionSort
29
/* self-identification: #endif constant */
30
31
/*--------------------------------------------------------------------------*/
32
/*------------------------------ INCLUDES ----------------------------------*/
33
/*--------------------------------------------------------------------------*/
34
35
#include "
ADS/Contract.h
"
36
#include "
ADS/search/Minimum.h
"
37
#include "
ADS/sort/Sorted.h
"
38
39
#include <algorithm>
40
#include <cstddef>
41
#include <functional>
42
#include <utility>
43
#include <vector>
44
45
/*--------------------------------------------------------------------------*/
46
/*--------------------------- NAMESPACE ------------------------------------*/
47
/*--------------------------------------------------------------------------*/
48
49
namespace
ADS
50
{
51
66
template
<
RankStore
Store ,
67
class
T = std::ranges::range_value_t< std::remove_cvref_t< Store > > ,
68
class
C = std::less<> >
69
void
selectionSort
( Store && A , C less = C() );
70
72
template
<
class
T ,
class
C = std::less<> >
73
void
selectionSort
( std::vector< T > & A , C less = C() );
74
75
/*--------------------------------------------------------------------------*/
76
/*------------------------- THE SORTS OF A RANGE ---------------------------*/
77
/*--------------------------------------------------------------------------*/
78
83
template
<
SortRange
R ,
class
... P >
84
requires
requires
( std::vector< std::ranges::range_value_t< R > > & v ,
85
P &&... p )
86
{
87
selectionSort
( v , std::forward< P >( p )... );
88
}
89
decltype
( auto )
selectionSort
( R && A , P &&... p )
90
{
91
const
auto
f = [ & ](
auto
& v ) ->
decltype
(
auto
) {
92
return
(
selectionSort
( v , std::forward< P >( p )... ) );
93
};
94
return
( detail::sortRange( A , f , f ) );
95
}
96
97
/*--------------------------------------------------------------------------*/
98
99
}
// end( namespace ADS )
100
101
/*--------------------------------------------------------------------------*/
102
/*-------------------------- IMPLEMENTATION --------------------------------*/
103
/*--------------------------------------------------------------------------*/
104
105
#include "ADS/sort/impl/SelectionSort.tpp"
106
107
/*--------------------------------------------------------------------------*/
108
109
#endif
/* SelectionSort.h included */
110
111
/*--------------------------------------------------------------------------*/
112
/*------------------------ End File SelectionSort.h ------------------------*/
113
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Minimum.h
The minimum of a vector (section 1.2): min() keeps the minimum so far and compares it with each of t...
Sorted.h
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
ADS::RankStore
the storage on which the sorts of the book work in place, which read the items by their ranks only: a...
Definition
Sorted.h:184
ADS::SortRange
a range that the sorts take beside std::vector and std::span: random access, sized,...
Definition
Sorted.h:153
ADS::selectionSort
void selectionSort(Store &&A, C less=C())
in increasing order by less, by selection of the minimum
ADS
Definition
ADT.h:96
ADS
sort
SelectionSort.h
Generated by
1.17.0