数据结构-递归

二分法查找

package com.execlib.search;

/**
 * 二分法查找
 */
public class BinarySearch {
    public int search(int[] data,int key){
        return binarySearch(data,key,0,data.length-1);
    }

    public int binarySearch(int[] data,int key, int left, int right) {
        if (left>=right)
            return -1;
        int mid = (left+right)/2;
        if (data[mid]>key){
            right = mid-1;
        }else if (data[mid]

你可能感兴趣的:(数据结构-递归)