插入排序之直接插入排序:
/**
* @author Jay
* @date 2020/7/11 19:00
* @Description: 直接插入排序
*/
public class insertSort {
public int[] InsertSortP(int[] a) {
for (int i = 1; i < a.length; i++) {
int j = i - 1;
int temp = a[i];
while (j >= 0 && a[j] > temp) {
a[j + 1] = a[j];
--j;
}
a[j + 1] = temp;
}
return a;
}
}
因为是直接练习手写算法,就不做注释讲解算法和解析算法了,网上有很多博客详细讲算法原理的。