2.2 插值查找
- /* a是待搜索的顺序表,, size是a的长度, t 是待搜索的值 */
- int search(int a[], int size, int t)
- {
- int low = 0, high = size - 1;
- int pos;
- while(low <= high){
- pos = (t - a[low])/(a[high] - a[low])*(high - low) + low;
- if(a[pos] == t){
- return pos;
- }
- if(a[pos] > t){
- high = pos - 1;
- }else{
- low = pos + 1;
- }
- }
- return -1;
- }