|
ADS
Algorithms and Data Structures
|
Pigeonhole Sort (exercise 4.11) of the pairs \( ( \mathit{key} , \mathit{value} ) \) with keys in \( [ 0 , k ) \): the value of each pair goes at the end of the LIST of its key, then the lists are read in the order of the keys; \( O( n + k ) \) time, and stable, unlike Counting Sort, which only counts the keys. More...
#include "ADS/Contract.h"#include "ADS/sequence/List.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <stdexcept>#include <utility>#include <vector>#include "ADS/sort/impl/PigeonholeSort.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class V> | |
| std::vector< std::pair< int, V > > | ADS::pigeonholeSort (const std::vector< std::pair< int, V > > &A, int k) |
| the pairs sorted by key, the values of a key in their first order | |
Pigeonhole Sort (exercise 4.11) of the pairs \( ( \mathit{key} , \mathit{value} ) \) with keys in \( [ 0 , k ) \): the value of each pair goes at the end of the LIST of its key, then the lists are read in the order of the keys; \( O( n + k ) \) time, and stable, unlike Counting Sort, which only counts the keys.
The contracts [see Contract.h]: \( k \ge 0 \) and each key must be in \( [ 0 , k ) \), checked key by key, and the output has as many pairs as the input, its keys sorted. The functions are defined in PigeonholeSort.tpp.