#include<stdio.h>
#include<math.h>
int search(int A[],int key,int low,int high){
int mid;
if(low<=high){
mid=(low+high)/2;
if(low<=high && key<A[mid]){
printf("%d\n",A[mid]);
search(A,key,low,mid-1);
}
else if(low<=high && key>A[mid]){
printf("%d\n",A[mid]);
search(A,key,mid+1,high);
}
else if(low<=high && key==A[mid]){
printf("%d\n",A[mid]);
return 1;
}
}
else
return 0;
}
int main(){
//int A[10];
int A[15]={1,2,3,4,5,6,7,8,9,10};
int n=10;
if(search(A,0,0,n-1))
printf("查找成功\n");
else
printf("查找失败\n");
return 0;
}
递归二分查找
最新推荐文章于 2024-09-02 23:59:23 发布