十大排序算法全面解析-Java 实现
https://juejin.im/post/5c40837751882525487c5394
常用的排序算法的时间复杂度和空间复杂度
https://blog.csdn.net/wuxinyicomeon/article/details/5996675
排序算法的实现及性能分析
http://839299993.iteye.com/blog/2197845
java 代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public static int[] selectSort(int[] ary) { for (int i = 0; i < ary.length - 1; i++) { for (int j = i + 1; j < ary.length; j++) { if (ary[i] > ary[j]) { int t = ary[i]; ary[i] = ary[j]; ary[j] = t; } } } return ary; }
public static int[] bubbleSort(int[] ary) { for (int i = 0; i < ary.length - 1; i++) { for (int j = 0; j < ary.length - i - 1; j++) { if (ary[j] > ary[j + 1]) { int t = ary[j]; ary[j] = ary[j + 1]; ary[j + 1] = t; } } } return ary; }
public static int[] insertSort(int[] ary) { int i, j, t; for (i = 1; i < ary.length; i++) { t = ary[i]; for (j = i - 1; j >= 0 && t < ary[j]; j--) { ary[j + 1] = ary[j]; }
ary[j + 1] = t; } return ary; }
|
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏