mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
11 lines
332 B
C
11 lines
332 B
C
//插值查找
|
|
int InsertionSearch(int a[], int value, int low, int high)
|
|
{
|
|
int mid = low+(value-a[low])/(a[high]-a[low])*(high-low);
|
|
if(a[mid]==value)
|
|
return mid;
|
|
if(a[mid]>value)
|
|
return InsertionSearch(a, value, low, mid-1);
|
|
if(a[mid]<value)
|
|
return InsertionSearch(a, value, mid+1, high);
|
|
} |