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/d89/insertion__sort__recursive_8cpp_source.html below:

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

Go to the documentation of this file. 52 for

(

int

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

55 while

(j >= 0 && temp < arr[j]) {

71 size_t

n = arr->size();

73 for

(

size_t

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

76 while

(j >= 0 && temp < arr->at(j)) {

77

arr->at(j + 1) = arr->at(j);

80

arr->at(j + 1) = temp;

96 double

r = (std::rand() % 10000 - 5000) / 100.f;

97

arr[N] =

static_cast<

T

>

(r);

106 int

arr1[10] = {78, 34, 35, 6, 34, 56, 3, 56, 2, 4};

107

std::cout <<

"Test 1... "

;

109

assert(std::is_sorted(arr1, arr1 + 10));

110

std::cout <<

"passed"

<< std::endl;

112 int

arr2[5] = {5, -3, 7, -2, 1};

113

std::cout <<

"Test 2... "

;

115

assert(std::is_sorted(arr2, arr2 + 5));

116

std::cout <<

"passed"

<< std::endl;

118 float

arr3[5] = {5.6, -3.1, -3.0, -2.1, 1.8};

119

std::cout <<

"Test 3... "

;

121

assert(std::is_sorted(arr3, arr3 + 5));

122

std::cout <<

"passed"

<< std::endl;

124

std::vector<float> arr4({5.6, -3.1, -3.0, -2.1, 1.8});

125

std::cout <<

"Test 4... "

;

127

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

128

std::cout <<

"passed"

<< std::endl;

131

std::cout <<

"Test 5... "

;

134

assert(std::is_sorted(arr5, arr5 + 50));

135

std::cout <<

"passed"

<< std::endl;

138

std::cout <<

"Test 6... "

;

141

assert(std::is_sorted(arr6, arr6 + 50));

142

std::cout <<

"passed"

<< std::endl;

static void tests()

self test implementation

static void create_random_array(T *arr, int N)

Helper function to create a random array.

int main()

Main function.

void insertionSort(T *arr, int n)

Insertion Sort Function.


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