标签:style blog color ar java sp div c log
java实现:
package sort; public class BinarySearch { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] a={70,80,31,37,10,1,48,60,33,80}; QuickSort.quickSort(a); System.out.println(binarySearch(a,31)); } private static int binarySearch(int[] a, int element) { // TODO Auto-generated method stub int low,min,upper; low=0; upper=a.length-1; while(low<=upper){ min=(low+upper)/2; if(a[min]>element) upper=min-1; else if(a[min]<element) low=min+1; else return min; } return -1; } }
标签:style blog color ar java sp div c log
原文地址:http://www.cnblogs.com/huangcongcong/p/4004162.html