直接插入排序

xiaoxiao2021-02-28  93


直接插入排序思想:不断将无序区中的记录插入到有序区中。

public void insertSort(int[] array) { int length = array.length; for (int i = 1; i < length; i++) { if (array[i] < array[i - 1]) { int temp = array[i]; int j = i - 1; while (j >= 0 && array[j] > temp) { array[j + 1] = array[j]; j--; } array[j + 1] = temp; } } }
转载请注明原文地址: https://www.6miu.com/read-28464.html

最新回复(0)