分块查找 转载自https://www.cnblogs.com/Ming8006/p/8330481.html

感觉用不到  我就随便敲了敲代码。

package com.ldy.arithmetic.search;

import org.apache.tomcat.jni.Error;

import java.util.ArrayList;
import java.util.Arrays;

public class BlockBinarySearch {

    private int[] ints;
    private ArrayList[] lists;

    public BlockBinarySearch(){

    }
    public  BlockBinarySearch(int[] ints) throws Exception {
        if(ints !=null && ints.length>0){
            this.ints = ints;
            lists = new ArrayList[ints.length];
            for (int i=0;i ints[ints.length-1]){
//            throw new Exception("out of block range");
//        }
        int start = 0;
        int end = ints.length -1 ;
        int mid;
        while(start>>1;
            if(ints[mid]>data) end = mid - 1 ;
            else start=mid + 1;
        }
        return start;
    }

    public static void main(String[] args) throws Exception {
        int[] ints=new int[]{10,20,30,40,50,60};
        BlockBinarySearch blockBinarySearch=new BlockBinarySearch(ints);
//        System.out.println(Arrays.toString(ints));
        blockBinarySearch.insert(6);
        blockBinarySearch.insert(7);
        blockBinarySearch.insert(50);
        blockBinarySearch.insert(19);
        blockBinarySearch.insert(20);
        blockBinarySearch.insert(25);
        blockBinarySearch.insert(500);

//        blockBinarySearch.search(1);
//        blockBinarySearch.search(2);
//        blockBinarySearch.search(3);
//        blockBinarySearch.search(5);
//        blockBinarySearch.search(6);
//        blockBinarySearch.search(7);
        System.out.println(Arrays.toString(blockBinarySearch.lists));
    }
}

 

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