Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Create interpolation_sort.cpp #683

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions CPP/interpolation_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if (ar[mid] < value)
{
low = mid + 1;
}
else if (ar[mid] > value)
{
low = mid - 1;
}
else
{
return mid;
}
}

if (ar[low] == value)
{
return low;
}
else
{
return -1;
}
}
int main()
{
int ar [] = {1, 2, 78, 18, 16, 30, 29, 2, 0, 199};
int value, pos;

cout << "Your Array : ";
print_ar (ar, 10);

cout << "Enter the value to search : ";
cin >> value;
pos = interpolation_search (ar, value, 10);
if (pos != -1)
{
cout << "Value Found! at position : " << pos + 1 << endl;
}
else
{
cout << "Sorry, the value you searched for is not present." << endl;
}

return 0;
}