Lynwnujdx

默默无闻但努力上进的程序员

导航

2011年2月24日 #

二分查找法例子

摘要: 使用二分查找法的前提是:数组里的元素必须为有序的。public class Test { public static void main(String[] args) { int[] arr = new int[]{1,4,5,6,8,10,33,55,66}; int result = search(arr,40); System.out.println(result); } private static int search(int[] arr, int target){ int start = 0; int end = arr.length - 1; int middle = (end 阅读全文

posted @ 2011-02-24 10:23 Fly龙 阅读(410) 评论(0) 推荐(0)