摘要:前面三期分別寫了三篇簡單排序的算法,今天來說一點稍微難一點的排序算法-----插入排序。算法
package liuenci.cn.package_3; public class HomeWork { public static void main(String[] args) { int a[] = { 38,65,97,76,13,27,49 }; insertSort(a); for(int i:a){ System.out.print(i +" "); } } public static void insertSort(int[] a) { int i, j, insertNote; for (i = 1; i < a.length; i++) { insertNote = a[i]; j = i - 1; while (j >= 0 && insertNote < a[j]) { a[j + 1] = a[j]; j--; } a[j + 1] = insertNote; } } }