日期:2014-05-20  浏览次数:20613 次

java.util.Arrays中的一个方法,有问题呀,你们觉得呢?
Java code

    /**
     * Sorts the specified sub-array of longs into ascending order.
     */
    private static void sort1(long x[], int off, int len) {
    // Insertion sort on smallest arrays
    if (len < 7) {
        for (int i=off; i<len+off; i++)
        for (int j=i; j>off && x[j-1]>x[j]; j--)
            swap(x, j, j-1);
        return;
    }




------解决方案--------------------
没看出来
------解决方案--------------------
是你有问题。这是标准的排序。从小到大的顺序。
假设off为0,j=0不做操作,j=1,比较j与j-1的大小,j-1大就交换顺序,
j=2,则比较j=0,1,2的顺序。
依次类推大数逐渐下沉。