插入排序5
package ch02; public class InsertSort { public static void sort(long[] arr) { long tmp = 0; for(int i = 1; i < arr.length; i++) { tmp = arr[i]; int j = i; while(j > 0 && arr[j] >= tmp) { arr[j] = arr[j - 1]; j--; } arr[j] = tmp; } } } package ch02; public class TestBublleSort { public static void main(String[] args) { long[] arr = new long[4]; arr[0] = 34; arr[1] = 23; arr[2] = 2; arr[3] = 1; //BublleSort.sort(arr); //SelectionSort.sort(arr); InsertSort.sort(arr); System.out.print("{"); for(long num:arr){ System.out.print(num+" "); } System.out.println("}"); } }