谢谢以上各位。已经搞定了。
- public static void zBCZ(int[] arr,int key)
- {
- int e = arr.length-1;
- int s = 0;
- search(arr,key,s,e);
- }
- private static void search(int[] arr,int key,int s,int e)
- {
- int count = 0;
- if(s>e)
- return;
- int mid = (s+e)/2;
- if(arr[mid]>key)
- search(arr,key,s,mid-1);
- else if(arr[mid]<key)
- search(arr,key,mid+1,e);
- else
- {
- search(arr,key,s,mid-1);
- count = mid+1;
- System.out.println(key+"的位置是"+count);
- search(arr,key,mid+1,e);
- }
-
-
- }
复制代码
|