标签:printf int key arch 二分 查找 递归 sea pre
#include <stdlib.h>
#include <stdio.h>
//二分查找非递归
int Binary_Search(int list[],int key,int length){
int low=0,high=length-1;
while (low<=high){
int mid=(high+low)/2;
if (list[mid]==key)
return ++mid;
else if (list[mid]>key)
high=mid-1;
else if (list[mid]<key)
low=mid+1;
}
return -1;
}
int main(){
int list[10]={1,3,5,6,7,8,9,10,11,19};
int number=Binary_Search(list,10,10);
printf("%d",number);
return 0;
}
标签:printf int key arch 二分 查找 递归 sea pre
原文地址:https://www.cnblogs.com/szj666/p/13405912.html