标签:blog class code java int 2014
public class Sort { static void insertSort(int a[], int n) { for (int i = 1; i < n; i++) { if (a[i] < a[i - 1]) { int temp = a[i]; int k = i - 1; while (k >= 0 && a[k] > temp) { a[k + 1] = a[k]; k--; } a[k + 1] = temp; } } } public static void main(String[] args) { int a[] = { 3, 2, 5, 7, 8, 9, 4, 1, 0, 4, 6 }; insertSort(a, a.length ); for (int i : a) { System.out.print(i + " "); } } }
标签:blog class code java int 2014
原文地址:http://blog.csdn.net/hackcoder/article/details/25193311