//折半查找
void seachfornum(int arr[],int len,int key){
int low=0;
int high=len-1;
for(int i=0;i<len;i++){
printf("%d\t",arr[i]);
}
printf("\n");
while (min<max) {
int mid=(max+min)/2;
if(arr[mid]>key){
max=mid-1;
}else if (arr[mid]<key){
min=key+1;
}else{
return mid;
}
}
return -1;
}
|
|