标签:
1 package iYou.neugle.search; 2 3 public class Binary_search { 4 public static int BinarySearch(double[] array, double key) { 5 int left = 0; 6 int right = array.length - 1; 7 while (left <= right) { 8 int mid = (left + right) / 2; 9 if (array[mid] == key) { 10 return mid; 11 } else if (array[mid] > key) { 12 right = mid - 1; 13 } else if (array[mid] < key) { 14 left = mid + 1; 15 } 16 } 17 return -1; 18 } 19 }
标签:
原文地址:http://www.cnblogs.com/niuxiaoha/p/4624891.html