算法自学


1 二分查找法(binarySearch)
public static int rank(int key,int[] arr){//this arr is ordered array;
    int low =0;
    int height = arr.legth-1;
    while(low<=height){
        int mind = low + (height-low)/2;
        if(key==arr[mind]) return mind;
        else if (key>arr[mind}) low = mind+1;
        else height=mind-1;
    }
    return -1;
}


你可能感兴趣的:(算法,算法)