int64_t
binary_search(std::vector<T> &arr, T val, int64_t low, int64_t high) {
65 return(val > arr[low]) ? (low + 1) : low;
67int64_t mid = low + (high - low) / 2;
70}
else if(arr[mid] < val) {
85int64_t n = arr.size();
87 for(int64_t i = 1; i < n; i++) {
108std::vector<int64_t> arr1({5, -3, -1, -2, 7});
109std::cout <<
"1st test... ";
111assert(std::is_sorted(std::begin(arr1), std::end(arr1)));
112std::cout <<
"passed"<< std::endl;
116std::vector<int64_t> arr2({12, 26, 15, 91, 32, 54, 41});
117std::cout <<
"2nd test... ";
119assert(std::is_sorted(std::begin(arr2), std::end(arr2)));
120std::cout <<
"passed"<< std::endl;
124std::vector<float> arr3({7.1, -2.5, -4.0, -2.1, 5.7});
125std::cout <<
"3rd test... ";
127assert(std::is_sorted(std::begin(arr3), std::end(arr3)));
128std::cout <<
"passed"<< std::endl;
132std::vector<float> arr4({12.8, -3.7, -20.7, -7.1, 2.2});
133std::cout <<
"4th test... ";
135assert(std::is_sorted(std::begin(arr4), std::end(arr4)));
136std::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