|
ADS
Algorithms and Data Structures
|
The strand sort, beyond the book, on a list with pointers [see List.h]: a strand, i.e., the first item and every later one not smaller than the last taken, is pulled out of the list and merged with the result, until the list is empty. More...
#include "ADS/Contract.h"#include "ADS/sequence/List.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <cstddef>#include <functional>#include <utility>#include <vector>#include "ADS/sort/impl/StrandSort.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T, class C = std::less<>> | |
| void | ADS::strandSort (List< T > &L, C less=C(), std::size_t *strands=nullptr) |
| the strand sort of a list; the number of strands goes to *strands, if given | |
The strand sort, beyond the book, on a list with pointers [see List.h]: a strand, i.e., the first item and every later one not smaller than the last taken, is pulled out of the list and merged with the result, until the list is empty.
Pulling a strand and merging it cost \( O( n ) \) each, and there are as many strands as the items of a longest strictly decreasing subsequence: \( O( n ) \) on a sorted list and \( O( n^2 ) \) on a decreasing one. It is stable, as the natural merge sort of which it is a variant.
The contracts [see Contract.h]: the list ends sorted, an audit. The function is defined in StrandSort.tpp.