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/d8/dcc/binary__insertion__sort_8cpp_source.html below:

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

Go to the documentation of this file. 63

int64_t

binary_search

(std::vector<T> &arr, T val, int64_t low, int64_t high) {

65 return

(val > arr[low]) ? (low + 1) : low;

67

int64_t mid = low + (high - low) / 2;

70

}

else if

(arr[mid] < val) {

85

int64_t n = arr.size();

87 for

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

108

std::vector<int64_t> arr1({5, -3, -1, -2, 7});

109

std::cout <<

"1st test... "

;

111

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

112

std::cout <<

"passed"

<< std::endl;

116

std::vector<int64_t> arr2({12, 26, 15, 91, 32, 54, 41});

117

std::cout <<

"2nd test... "

;

119

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

120

std::cout <<

"passed"

<< std::endl;

124

std::vector<float> arr3({7.1, -2.5, -4.0, -2.1, 5.7});

125

std::cout <<

"3rd test... "

;

127

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

128

std::cout <<

"passed"

<< std::endl;

132

std::vector<float> arr4({12.8, -3.7, -20.7, -7.1, 2.2});

133

std::cout <<

"4th test... "

;

135

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

136

std::cout <<

"passed"

<< std::endl;

static void test()

Self-test implementations.

int main()

Main function.

int64_t binary_search(std::vector< T > &arr, T val, int64_t low, int64_t high)

Binary search function to find the most suitable pace for an element.

void insertionSort_binsrch(std::vector< T > &arr)

Insertion sort function to sort the vector.


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