- public int binarySearch(int[] BinarySearchArray,int k,int low,int high)//k为要查找的具体数据,low为低位,high为高位
- {
-
-
- int mid=0;
-
- while(low<=high)
- {
-
- //mid=(low+high)/2;
- mid=(low+high)>>2//右移相当于除2
-
- if(BinarySearchArray[mid]==k)
- return mid;
- else if(BinarySearchArray[mid]>k)
- high=mid-1;
- else if(BinarySearchArray[mid]<k)
- low=mid+1;
- }
-
- return 0;
-
- }
复制代码
|
|