fun(arr, low, high, key){ if(low > high){ return -1; } var mid = (high + low)/2; if( arr[mid] == key){ return mid; }else if( arr[mid] > key ){ high = mid - 1; return fun(arr, low, high, key); }else if( arr[mid] < key ){ high = mid + 1; return fun(arr, low, high, key); } } var arr = [1,2,3,4,5,6,7,8,9,10,11,23,44,86]; var result = fun(arr, 0, 44, 10); alert(result);
Caballarii
相关分类