二分查找法|二分查找法

package com.xcx.spots.test;
/**

  • @ProjectName: spots
  • @Package: com.xcx.spots.test
  • @ClassName: erfenchazhao
  • @Author: nh
  • @Description:
  • @Date: 2020/6/17 18:24
  • @Version: 1.0
    */
【二分查找法|二分查找法】public class erfenchazhao {
/** * @desc 二分查询(非递归方式) * 案例: * {1,3,8,10,11,67,100},编程实现二分查找,要求使用非递归方式完成。 * @Author xw * @Date 2019/9/27 */ public static void main(String[] args) { int[] arr = {1, 3, 8, 10, 11, 67, 100}; int index = binarySearch(arr, 11); if (index != -1) { for (int i=0; i target) { right = mid - 1; // 向左找 } else { left = mid + 1; // 向右找 } } return -1; }

}

    推荐阅读