标签:code alt style png 二分查找 nbsp else log 技术
#include <stdio.h>
#define N 6
int f(int a[],int low,int high,int x)
{
int mid =(low+high)/2 ;
if (low>high) return -1 ;
else if (a[mid]==x) return mid ;
else if (a[mid]>x ) return f(a,low,mid-1,x);
else return f(a,mid+1, high,x);
}
int main ( )
{
int x, a[N]={ 1,2,3,5,6,7} ;
scanf("%d",&x);
printf("%d\n",f(a,0,N-1,x));
}<br><br>********************************************************<br><br><br>
#include <stdio.h>
#define N 6
int f(int a[],int low,int high,int x)
{
int mid =(low+high)/2 ;
if(low>high) return -1 ;
if(a[mid]==x) return mid ;
if(a[mid]>x) return f(a,low,mid-1,x);
else return f(a,mid+1, high,x);
}
int main ( )
{
int x, a[N]={ 1,2,3,5,6,7} ;
scanf("%d",&x);
printf("%d\n",f(a,0,N-1,x));
}
标签:code alt style png 二分查找 nbsp else log 技术
原文地址:http://www.cnblogs.com/wangprince2017/p/7680386.html