ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Rearrangements.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File Rearrangements.h --------------------------*/
3/*--------------------------------------------------------------------------*/
69/*--------------------------------------------------------------------------*/
70/*----------------------------- DEFINITIONS --------------------------------*/
71/*--------------------------------------------------------------------------*/
72
73#ifndef __ADS_Rearrangements
74 #define __ADS_Rearrangements
75/* self-identification: #endif constant */
76
77/*--------------------------------------------------------------------------*/
78/*------------------------------ INCLUDES ----------------------------------*/
79/*--------------------------------------------------------------------------*/
80
81#include "ADS/Contract.h"
82#include "ADS/sort/Sorted.h"
83
84#include <algorithm>
85#include <cstddef>
86#include <functional>
87#include <numeric>
88#include <type_traits>
89#include <utility>
90#include <vector>
91
92/*--------------------------------------------------------------------------*/
93/*--------------------------- NAMESPACE ------------------------------------*/
94/*--------------------------------------------------------------------------*/
95
96namespace ADS
97{
98
123template< class T , class F >
124std::pair< std::size_t , std::size_t >
125dutchNationalFlag( std::vector< T > & A , F && color ,
126 std::size_t * swaps = nullptr );
127
146template< class T , class C = std::less<> >
147void wiggleSort( std::vector< T > & A , C less = C() );
148
171template< class T , class C = std::less<> >
172void sortKSorted( std::vector< T > & A , std::size_t k , C less = C() );
173
201template< class T , class W = T >
202 requires std::is_arithmetic_v< T >
203std::pair< std::size_t , W > minimumSwapSort( const std::vector< T > & A );
204
205/*--------------------------------------------------------------------------*/
206
207} // end( namespace ADS )
208
209/*--------------------------------------------------------------------------*/
210/*-------------------------- IMPLEMENTATION --------------------------------*/
211/*--------------------------------------------------------------------------*/
212
213#include "ADS/sequence/impl/Rearrangements.tpp"
214
215/*--------------------------------------------------------------------------*/
216
217#endif /* Rearrangements.h included */
218
219/*--------------------------------------------------------------------------*/
220/*----------------------- End File Rearrangements.h ------------------------*/
221/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
std::pair< std::size_t, std::size_t > dutchNationalFlag(std::vector< T > &A, F &&color, std::size_t *swaps=nullptr)
the items of by color( x ), 0 then 1 then 2, with reads of the colors and at most swaps,...
void sortKSorted(std::vector< T > &A, std::size_t k, C less=C())
sorted, each item at most places away from its place in the sorted order, by a heap of items;
void wiggleSort(std::vector< T > &A, C less=C())
, by swaps of neighbors; comparisons
std::pair< std::size_t, W > minimumSwapSort(const std::vector< T > &A)
the fewest swaps that sort , and the least total cost of the swaps that sort it, a swap costing the s...
Definition ADT.h:96