六 简单排序之插入排序

思想:i 从1往后走,

j 往前走找到插入的位置,然后插入进去。

原理

源代码:

public class insertSort {
public static void sort(int[] array) //插入排序
{
int temp =0; //中间变量
for(int i=1;i<array.length;i++)
{
temp =array[i];
int j =i-1;
while(j>0 && array[j] >temp ) //往前挪动
{
array[j] = array[j-1];
j--;
}
array[j] =temp;

}
}
}

原文地址:https://www.cnblogs.com/fyz666/p/8455390.html