- public static void zhong(int[] arr, int key) {
- int min = 0, max = arr.length - 1, mid = (min + max) / 2;
- while (arr[mid] != key) {
- if (arr[mid] < key) {
- min = mid + 1;
- } else if (arr[mid] > key) {
- max = mid - 1;
- }
- mid = (min + max) / 2;
- if (min > max) {
- System.out.println("没有找到!");
- return;
- }
- }
- System.out.println(mid + " " + arr[mid]);
- }
复制代码 哈哈 |
|