插入排序

这次用了比较简洁的方式来写,每次都交换两数而不是单纯移项,可能会慢一点,但代码很漂亮。

public static void insertionSort(int[] A){
    for(int i = 1; i < A.length; i ++){
        for(int j = i-1; j >= 0 && A[j] > A[j+1]; j --){
            swap(A, j, j+1);
        }
    }
}
Java
原文地址:https://www.cnblogs.com/7hat/p/3381322.html