1 import java.util.Scanner; 2 3 /** 4 * @author Administrator 递归算法折半查找 5 */ 6 public class zhebanchazhao_1 { 7 8 public static void main(String[] args) { 9 10 int[] a = new int[100];11 int x;12 Scanner cin = new Scanner(System.in);13 14 x = cin.nextInt();15 for (int i = 0; i < x; i++) {16 a[i] = cin.nextInt();17 }18 int b = cin.nextInt();19 System.out.println(IterBiSearch(a, b, 0, x));20 21 }22 23 public static int IterBiSearch(int data[], int x, int beg, int last) {24 int mid = -1;25 mid = (beg + last) / 2;26 if (x == data[mid]) {27 return mid;28 } else if (x < data[mid]) {29 return IterBiSearch(data, x, beg, mid - 1);30 } else if (x > data[mid]) {31 return IterBiSearch(data, x, mid + 1, last);32 }33 return -1;34 }35 36 }