/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.datastructure;

/**
 * @author cwenao
 * @version $Id BinarySearch.java, v 0.1 2017-07-18 13:12 cwenao Exp $$
 */
public class BinarySearch {

    private static int recursionBinarySearch(int[] array, int targetNum, int low, int high) {

        if (array == null || array.length == 0) {
            return -1;
        }
        if (low >= high) {
            return -1;
        }

        int mid = (low + high) / 2;
        if (array[mid] == targetNum) {
            return mid;
        }
        if (targetNum > array[mid]) {
            return recursionBinarySearch(array, targetNum, mid + 1, high);
        } else {
            return recursionBinarySearch(array, targetNum, low, mid - 1);
        }
    }

    public static void main(String[] args) {
        int[] array = {1, 3, 4, 5, 8, 11, 42, 66, 78, 90, 114, 256};
        int targetNum = 11;
        int low = 0;
        int high = array.length;

        int index = recursionBinarySearch(array, targetNum, low, high-1);
        System.out.println("The index for targetNum is : " + index);
    }

}


@@ -99,16 +99,34 @@
 e;%0A%0A/**%0A
+ * %E5%9C%A8%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE%E7%9A%84%E6%8C%89%E7%85%A7%E6%95%B0%E7%BB%84%E6%9C%89%E5%BA%8F%E8%BF%9B%E8%A1%8C%0A
  * @auth

update the project