提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
二进制搜索int数组
public class Main {/*时代Java - nowjava.com*/ public static boolean binarySearch(int arr[], int low, int high){ int first = 0; int last = arr.length -1; while (last > first){ int middle = first + (last - first)/2; if (arr[middle] >= low && arr[middle] <= high){ return true; } else if (arr[middle] < low){ first = middle + 1; } else last = middle -1; /* n o w j a v a . c o m - 时 代 Java 提供 */ } return false; } public static