java-二分查找法

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 -;
}
}
上一篇:nginx 502 Bad Gateway 错误解决办法


下一篇:html5游戏开发框架之lufylegend开源库件学习记录