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/d9/dd7/interpolation__search_8cpp_source.html below:

TheAlgorithms/C++: search/interpolation_search.cpp Source File

50namespace

interpolation_search {

58

uint64_t interpolationSearch(

const

std::vector<uint64_t> &arr,

60

uint64_t size = arr.size();

61

uint64_t low = 0, high = (size - 1);

65 while

(low <= high && number >= arr[low] && number <= arr[high]) {

67 if

(arr[low] == number) {

75

((

static_cast<

uint64_t

>

(high - low) / (arr[high] - arr[low])) *

78 if

(arr[pos] == number) {

82 if

(arr[pos] < number) {

101static void tests

() {

105

std::vector<uint64_t> arr = {{10, 12, 13, 16, 18, 19, 20, 21, 1, 2, 3, 4,

106

22, 23, 24, 33, 35, 42, 47}};

107

sort(arr.begin(), arr.end());

108

uint64_t number = 33;

109

uint64_t expected_answer = 15;

110

uint64_t derived_answer =

111

search::interpolation_search::interpolationSearch(arr, number);

112

std::cout <<

"Testcase: "

;

113

assert(derived_answer == expected_answer);

114

std::cout <<

"Passed!\n"

;

int main()

Main function.

Testcases to check Union of Two Arrays.


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