//直接插入排序(无哨兵) 通过测试 public class InsertSortTest{ public static void insertSort(int[] arr) { for (int i = 1; i < arr.length; i++) { if (arr[i] < arr[i - 1]) { int temp = arr[i]; int j; for (j = i - 1; j >= 0 && temp < arr[j]; j--) { arr[j + 1] = arr[j]; } arr[j + 1] = temp; } } } //----------------------------------------------------------------------------- public static void main(String[] args){ int x[]={9,8,7,6,5,4,3,2,1}; insertSort(x); for(int i=0;i<=x.length-1;i++){ System.out.println(x[i]); } } }