int CRandom::interpolationSearch(int search_key, int key[], int n)
{
int index=0, low =0, high=NUM-1, output=0;
cnt=0;
while(low <= high && output ==0)
{
cnt++;
if(search_key == key[index]){
output=index;
return(index+1);
}
else{
// printf("index = %dt",index);
index=low + (int)((float)((search_key-key[low])*(high-low))/(key[high]-key[low]));
}
if (search_key < key[index]){
high=index-1;
}
else{
low=index+1;
}
}
return index+1;
}
{
int index=0, low =0, high=NUM-1, output=0;
cnt=0;
while(low <= high && output ==0)
{
cnt++;
if(search_key == key[index]){
output=index;
return(index+1);
}
else{
// printf("index = %dt",index);
index=low + (int)((float)((search_key-key[low])*(high-low))/(key[high]-key[low]));
}
if (search_key < key[index]){
high=index-1;
}
else{
low=index+1;
}
}
return index+1;
}
댓글 달기