Applying interpolation search algorithm

We can use the main() function similar to binary search to find the value 16as shown in the following code:

int main(){    cout << "Interpolation Search" << endl;    // Initialize a new array    int arr[] = {3, 8, 11, 15, 16, 23, 28, 30, 32, 39, 42, 44, 47,      48, 50};    int arrSize = sizeof(arr)/sizeof(*arr);    // Define value to be searched    int searchedValue = 16;    // Find the searched value using Interpolation Search    int i = InterpolationSearch(arr, 0, arrSize - 1,      searchedValue);    // Notify user the result    // if the return is not -1,    // the searched value is found    if(i != -1)    {        cout << searchedValue << " is found in index ";        cout << i << endl;    }    else    {        cout << "Could not find value " << searchedValue; cout << ...

Get C++ Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.