标签:style div oid https 时间 tostring span 一个 复杂度
1 public class InsertSort { 2 3 public static void main(String[] args) { 4 int[] arr = {100, 30, 70, 20, 80, 60, 40, 50, 90, 10}; 5 arr = insertSort(arr); 6 System.out.println(Arrays.toString(arr)); 7 } 8 9 private static int[] insertSort(int[] arr) { 10 if (arr == null || arr.length < 2) { 11 return arr; 12 } 13 for (int i = 0; i < arr.length; i++) { 14 for (int j = i; j > 0; j--) { 15 if (arr[j] < arr[j - 1]){ 16 int temp = arr[j]; 17 arr[j] = arr[j - 1]; 18 arr[j - 1] = temp; 19 }else { 20 break; 21 } 22 } 23 } 24 return arr; 25 } 26 }
标签:style div oid https 时间 tostring span 一个 复杂度
原文地址:https://www.cnblogs.com/buwei/p/10080668.html