摘要:#include <stdio.h>
#include <stdlib.h>
int NBinarySearch(int a[],int x,int n)
{ int low = 0,high = n-1;
while(low<=high)
#include <stdio.h>
#include <stdlib.h>
int NBinarySearch(int a[],int x,int n)
{ int low = 0,high = n-1;
while(low<=high)
{
int middle = (low+high)/2;
if (x==a[middle]) return middle;
else if (x>a[middle]) low=middle+1;
else high=middle-1;
}
return -1;
}
int main()
{
int b[]={1,2,3,4,5,6,7,8,9,10};
printf("%d\n",NBinarySearch(b,7,10));
return 0;
}