int search_seq(int *A,int len,int key){
A[0] = key; //"哨兵"
for(i=len;A[i]!=key;--i);
return i;
}
版本一:
int bin_search(){
int low=0;high=L.len-1,mid;
while(low<=high){
mid=(low+high)/2;
if(L.elem[mid]==key)
return mid;
else if(L.elem[mid]>key)
high=mid-1;
else
low=mid+1;
}
return -1;
}
版本二:
//二分查找
int vector_bin_search(struct vector v,int e,int lo,int hi)
{
while (lo<hi) {
int mi = (lo+hi)>>1;
if(e<*(v.elem+mi)){
hi = mi;
}else{
lo = mi + 1;
}
}
return --lo;
}
最理想的块长为