二分法查找return 问题
程序代码:
#include<stdio.h> #define ARRAY_LENGTH 10 int binarySearch(int num[],int first,int last,int target){ int mid=(first+last)/2; printf("%d\n",mid); if(num[mid]<target){ binarySearch(num,mid,last,target); } if(num[mid]>target){ binarySearch(num,first,mid,target); } if(num[mid]==target){ printf("getin=%d\n",mid); return mid; } } main(){ int num[ARRAY_LENGTH]={1,2,3,4,5,6,7,8,9,10}; printf("result=%d\n",binarySearch(num,0,ARRAY_LENGTH-1,9)); }
无法将结果带回来,有谁知道原因的
[ 本帖最后由 Leeprison 于 2013-1-15 11:07 编辑 ]