第一反应下写出来的程序:
/**
    * 二分法查找(迭代实现)
    */

   public int query( int value, int start, int end) {
     if (start > end) {
       return 0;
    }
     if (start == end) {
       return this.array[start] == value ? 1 : 0;
    }
     int m = (end + start) / 2;
     if ( this.array[m] == value) {
       return 1;
    } else {
       if ( this.array[m] > value) {
        end = m;
      } else {
        start = m;
      }
       return this.query(value, start, end);
    }
  }
 
改进后的实现(非迭代):
   /**
    * 二分查找(非迭代)
    *    
    * @return
    */

   public boolean binaryQuery( int[] test, int target) {
     int low = 0;
     int high = test.length - 1;
     while (low <= high) {
       // 计算中间值的策略
       // 1:(high + low) / 2,可能溢出
       // 2: low + (high - low) / 2
       // 3: high+low>>>1 (无符号右移)
       int mid = high + low >>> 1;
       int midValue = test[mid];
       if (mid == low || mid == high) {
         return midValue == target;
      }
       if (midValue < target) {
        low = mid;
      } else if (midValue > target) {
        high = mid;
      } else {
         return true;
      }
    }
     return false;
  }