搜索算法

  1. 顺序搜索
function sequentialSearch(arr,target){
    for(let i=0; i
  1. 二分搜索
function binarySearch(target,arr,start,end) {
    var start = start
    var end = end
    var mid = parseInt((start+end)/2)
    if(target === arr[mid]){
        return mid
    }else if(target > arr[mid]){
        return binarySearch(target,arr,mid+1,end)
    }else{
        return binarySearch(target,arr,start,mid-1)
    }
    return -1;
}

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