自己整理的算法 (2)插入排序
package sort; //插入排序 public class InsertionSort { public static void insertionSort(int[] list){ for(int i=1 ;i<list.length;i++){ int currentElement = list[i]; int k ; for( k =i-1;k>=0&&list[k]>currentElement;k--) list[k+1]=list[k]; list[k+1] = currentElement; } } public static void main(String[] args){ int[] list ={5 , 1 , 6, 2 ,4}; insertionSort(list); for(int i =0;i<list.length;i++){ System.out.print(list[i]+" "); } } }