很长时间没有更新博客了,写篇插入排序,这小程序居然让我调了很长时间…… public class InsertSort{ public static void main(String[] args) { int[] t = {5,8,4,1,9,3}; insertSort(t); for(int b:t) { System.out.print(b+" "); } } public static void insertSort(int[] a){ for(int i=1;i<a.length;i++){ int temp = a[i]; int j; for(j=i;j>=1&&a[j-1]>temp;j--) { a[j]=a[j-1]; } a[j]=temp; } } } 结果: