插入排序

public static void insertionSort(int[] a) {
    for (int i = 1; i < a.length; i++) {
        int key = a[i];
        int j = i - 1;
        for (; j >= 0 && key < a[j]; j--) // asc
            a[j + 1] = a[j];
        a[j + 1] = key;
    }
}


Previous     Next
ponxu /
Categories 算法  Tags 算法