java-二分查找法

时间:2021-08-21 12:20:55
package search;

public class BinarySearch {
public static void main(String[] args) {
int[] arys = {, , , , , , , , };
System.out.println(binarySearch(arys, , , arys.length - ));
} private static int binarySearch(int[] arys, int element, int begin, int end) {
// TODO Auto-generated method stub
if (begin <= end) {
int mid = (begin + end) >> ;
if (arys[mid] == element)
return mid;
else if(arys[mid] > element) {
return binarySearch(arys, element, , mid - );
} else {
return binarySearch(arys, element, mid + , end);
}
} else
return -;
}
}