TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of [Pigeonhole Sort algorithm] (https://en.wikipedia.org/wiki/Pigeonhole_sort) More...
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | sorting |
for working with vectors | |
Functions | |
template<std::size_t N> | |
std::array< int, N > | sorting::pigeonSort (std::array< int, N > arr) |
static void | test_1 () |
static void | test_2 () |
static void | test_3 () |
int | main () |
Implementation of [Pigeonhole Sort algorithm] (https://en.wikipedia.org/wiki/Pigeonhole_sort)
Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same. It requires O(n + Range) time where n is number of elements in input array and ‘Range’ is number of possible values in array.
The time Complexity of the algorithm is \(O(n+N)\).
Definition in file pigeonhole_sort.cpp.
int main | ( | void | ) |
Main function
Definition at line 127 of file pigeonhole_sort.cpp.
|
static |
Test function 1 with unsorted array {8, 3, 2, 7, 4, 6, 8}
Definition at line 68 of file pigeonhole_sort.cpp.
|
static |
Test function 2 with unsorted array {802, 630, 20, 745, 52, 300, 612, 932, 78, 187}
Definition at line 88 of file pigeonhole_sort.cpp.
|
static |
Test function 1 with unsorted array {11,13,12,14}
Definition at line 109 of file pigeonhole_sort.cpp.