标签:io ar amp 算法 size sp c return
#include <stdio.h>
int BinSearch(int Source[],int size,int key)
{
int low=0, high=size-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(Source[mid] == key)
return mid;
if(Source[mid] > key)
high=mid-1;
else
low=mid+1;
}
return -1;
}
void main()
{
int num;
int index;
int ArraySource[10]={1,2,8,11,12,13,14,15,16,17};//Array after sorting
printf("Plese input the number to find\n");
scanf("%d",&num);
index=BinSearch(ArraySource,10,num);
if(index>=0)
printf("The number you are finding locates @ [%d]\n",index+1);
else
printf("The number is not in source array \n");
}
标签:io ar amp 算法 size sp c return
原文地址:http://my.oschina.net/lvyi/blog/304628