标签:index 描述 mamicode 排序算法 oid sort img private current
一般来说,插入排序都采用in-place在数组上实现。具体算法描述如下:
private static void sort(int[] arr) {
int length = arr.length;
int preIndex, current;
for (int i = 1; i < length; i++) {
preIndex = i - 1;
current = arr[i];
while (preIndex >= 0 && arr[preIndex] > current) {
arr[preIndex + 1] = arr[preIndex];
preIndex--;
count++;
}
arr[preIndex + 1] = current;
}
}
标签:index 描述 mamicode 排序算法 oid sort img private current
原文地址:https://www.cnblogs.com/StivenYang/p/13189305.html