Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

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 << ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content