首页 > 代码库 > 查找算法

查找算法

Array.prototype.search = function(value) {
    var arr = this;
    function search(arr, value, start, end) {
        if (start > end) {
            return -1;
        } else {
            var middle = start + end >> 1;
            if (value > arr[middle]) {
                return search(arr, value, middle + 1, end)
            } else if (value < arr[middle]) {
                return search(arr, value, start, middle - 1);
            } else if (value =http://www.mamicode.com/== arr[middle]) {>

  

Array.prototype.search = function(value) {
    var arr = this;
    function search(arr, value, start, end) {
        if (start > end) {
            return -1;
        } else {
            var middle = start + end >> 1;
            if (value > arr[middle]) {
                return search(arr, value, middle + 1, end)
            } else if (value < arr[middle]) {
                return search(arr, value, start, middle - 1);
            } else if (value =http://www.mamicode.com/== arr[middle]) {>

  

查找算法