本帖最后由 yekong262 于 2014-1-22 09:54 编辑
- public static int halfSearch_2(int[] arr,int key)
- {
- int min=0,max=arr.length,mid=(max+min)/2;
- while (min<=max)
- {
- mid=(max+min)/2;
- if (key>arr[mid])
- min=mid+1;
- else if (key <arr[mid])
- max=mid-1;
- else if(key==arr[mid])
- return mid;
-
- }
- return -1;
- }
复制代码 |