二分查找的递归与递推算法实现
int binary_find(int *p,int len,int data){ int left = 0; int rigth = len-1; while(left <= rigth){ int mid = (left + rigth)/2;//中间的下标 if(p[mid] == data){ return mid; }else if(data < p[mid]){ rigth = mid-1; }else{ left = mid+1; } } return -1; } int binaryFind(int *p,int left,int rigth,int data){ if(left > rigth){ return -1; } int mid = (left+rigth)/2; if(p[mid] == data){ return mid; }else if(data < p[mid]){ return binaryFind(p,left,mid-1,data); }else{ return binaryFind(p,mid+1,rigth,data); } }