JAVA分治合并排序(MERGE-SORT)

/**
 * 分治算法.
 */
public class MergeSort {

    private MergeSort() {
        throw new RuntimeException();
    }

    public static void sort(int[] array) {
        if (null == array||array.length<2) {
            return;
        }
        sort(0, array.length, array);
    }

    private static void sort(int start, int length, int[] array) {
        if (length > 2) {
            int middle = (int) Math.floor(length / 2);
            sort(start, middle, array);
            sort(start + middle, length - middle, array);
            merge(start, middle, start + middle, length - middle, array);
        } else if (length == 2) {
            if (array[start+1]

你可能感兴趣的:(JAVA分治合并排序(MERGE-SORT))