标签:
数据结构之折半查找
#include<stdio.h>
int Binary_Search(int *a,int n,int key){
int low,mid,high;
low = 1;
high = n;
while(low<=high){
mid=(low+high)/2;
if(key<a[mid])
high=mid-1;
else if(key>a[mid])
low=mid+1;
else
return mid;
}
return 0;
}
void main(){
int num[] = {0,1,16,24,35,47,59,62,73,88,99};
int result = Binary_Search(num,sizeof(num)/sizeof(num[0])-1,62);
printf("查找结果为:%d\n",result);
}
运行结果为:
标签:
原文地址:http://www.cnblogs.com/zhengjunfei/p/4713575.html