Ordinary insertion sort

Time complexity O(n^2)

public void sort(int[] a) {
    for (int i = 1; i < a.length; i++) {
        int temp = a[i];
        int j = i - 1;
        for (j = i - 1; j >= 0; j--) {
            if (a[j] >= temp) {
                a[j + 1] = a[j];
            } else {
                break;
            }
        }
        a[j + 1] = temp; }}Copy the code

Split insertion sort

Time complexity O(n*log(n))

public void sort(int[] a) {
    for (int i = 1; i < a.length; i++) {
        int temp = a[i];
        int low = 0;
        int high = i - 1;
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (a[mid] >= temp) {
                high = mid - 1;
            } else {
                low = mid + 1; }}for (int j = i - 1; j > high; j--) {
            a[j + 1] = a[j];
        }
        a[high + 1] = temp; }}Copy the code

Split half double interpolation sort

public void sort(int[] a) {
    for (int i = 1; i < a.length; i+=2) {
        int temp;
        int low;
        int high;
        if (i < a.length - 1) {
            int max = a[i] > a[i+1]? a[i] : a[i+1];
            int min = a[i] <= a[i+1]? a[i] : a[i+1];
            low = 0;
            high = i - 1;
            while (low <= high) {
                int mid = (low + high) >> 1;
                if (a[mid] >= max) {
                    high = mid - 1;
                } else {
                    low = mid + 1; }}for (int j = i - 1; j > high; j--) {
                a[j + 2] = a[j];
            }
            a[high + 2] = max;

            temp = min;
            low = 0;
        }else {
            temp = a[i];
            low = 0;
            high = i - 1;
        }
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (a[mid] >= temp) {
                high = mid - 1;
            } else {
                low = mid + 1; }}for (int j = i - 1; j > high; j--) {
            a[j + 1] = a[j];
        }
        a[high + 1] = temp;
    }
Copy the code

Hill sort (least incremental sort)

public void sort(int[] a) { for(int gap=a.length/2; gap>0; gap/=2){ for(int i=gap; i<a.length; i++){ int j = i; while(j-gap>=0 && a[j]<a[j-gap]){ int temp = a[j]; a[j] = a[j-gap]; a[j-gap] = temp; j -= gap; }}}}Copy the code