标签:style blog ar color os sp java div art
public class binarySearchTest { public static void main(String[] args) { int[] a = {1,5,9,36,49,89,102}; int c = 49; int pos = binarySearch(a,c); System.out.println(pos); } private static int binarySearch(int[] a, int c) { if(a.length == 0) return -1; int start = 0; int end = a.length - 1; int middle = (start + end) / 2; while(start <= end) { if(a[middle] == c) return middle; if(a[middle] < c) { start = middle + 1; } else { end = middle - 1; } middle = (start + end) / 2; } return -1; } }
标签:style blog ar color os sp java div art
原文地址:http://www.cnblogs.com/qql1986/p/4153448.html