A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/dd/da8/pigeonhole__sort_8cpp_source.html below:

TheAlgorithms/C++: sorting/pigeonhole_sort.cpp Source File

Go to the documentation of this file. 33template

<std::

size_t

N>

36 auto

min = std::min_element(std::begin(arr), std::end(arr));

37 auto

max = std::max_element(std::begin(arr), std::end(arr));

40 int

range = *max - *min + 1;

41 int

*hole =

new int

[range]();

44 for

(

int

i = 0; i < N; i++) {

45

hole[arr[i] - *min] = arr[i];

50 for

(

int

i = 0; i < range; i++) {

51 while

(hole[i] !=

'\0'

) {

70

std::array<int, n> test_array = {8, 3, 2, 7, 4, 6, 8};

74

assert(std::is_sorted(std::begin(test_array), std::end(test_array)));

77 for

(

int

i = 0; i < n; i++) {

78

std::cout << test_array.at(i) <<

" "

;

80

std::cout <<

"\nPassed\n"

;

90

std::array<int, n> test_array = {802, 630, 20, 745, 52,

91

300, 612, 932, 78, 187};

95

assert(std::is_sorted(std::begin(test_array), std::end(test_array)));

98 for

(

int

i = 0; i < n; i++) {

99

std::cout << test_array.at(i) <<

" "

;

101

std::cout <<

"\nPassed\n"

;

111

std::array<int, n> test_array = {11, 13, 12, 14};

115

assert(std::is_sorted(std::begin(test_array), std::end(test_array)));

118 for

(

int

i = 0; i < n; i++) {

119

std::cout << test_array.at(i) <<

" "

;

121

std::cout <<

"\nPassed\n"

;

std::array< int, N > pigeonSort(std::array< int, N > arr)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4