function binary-search(arr,key){
       var low=0,
           high=arr.length-1,
           mid=Math.floor((low+high)/2);
       while(low<=high){
           mid=Math.floor((low+high)/2);
           if(key==arr[mid]){
               return mid;
           }else if(key<arr[mid]){
               high=mid-1;
          }else{
              low=mid+1;
          }
      }
      return -1;
  }

有序数组中查找


_ipo
179 声望15 粉丝

bug