- #include "stdio.h"
- void Search(int p[],int low,int height,int key)
- {
- int middle=(low+height)/2;
- if(low>height)
- {
- printf("没有该数!");
- return;
- }
- if(p[middle]==key)
- {
- printf("%d\n",middle);
- return;
- }
- else if(p[middle]>key)
- {
- Search(p,low,middle-1,key);
- }
- else if(p[middle]<key)
- {
- Search(p,middle+1,height,key);
- }
- }
- int main()
- {
- int p[5]={1,2,3,4,5};
- Search(p,0,4,4);
- return 0;
- }
递归二分法查找
最新推荐文章于 2022-07-23 10:13:49 发布