public void directInsertSort(int [] data) { for(int i = 1; i < data.lenght; i++) { int temp = data[i]; for(int j = i - 1; j >= 0 && data[j] >= temp; j--) { //j处大于 则j~i-1处肯定也大于。所以是整体后移 data[j+1] = data[j]; } data[j+1] = temp; } }
public void directInsertSort(int [] data) { for(int i = 1; i < data.lenght; i++) { int temp = data[i]; for(int j = i - 1; j >= 0 && data[j] >= temp; j--) { //j处大于 则j~i-1处肯定也大于。所以是整体后移 data[j+1] = data[j]; } data[j+1] = temp; } }