排序算法

参考https://www.cnblogs.com/onepixel/p/7674659.html

1.冒泡排序

 1 /**
 2  * 排序算法-冒泡法
 3  * @param a
 4  * @return
 5  */
 6     public static int[] T(int[] a){
 7         int len = a.length;
 8         /*
 9          * 每次一趟(i+1表示多少趟)比较相邻两个元素,大的放后面,
10          */
11         //注意这里i<len-1而不是len
12         for (int i = 0; i < len - 1; i++) {
13             //j<len-1-i
14             for (int j = 0; j < len - 1 - i; j++) {
15                 if (a[j] > a[j+1]) {        // 相邻元素两两对比
16                     int temp = a[j+1];        // 元素交换
17                     a[j+1] = a[j];
18                     a[j] = temp;
19                 }
20             }
21         }
22         return a;
23     }

2.选择排序

5、归并排序

原文地址:https://www.cnblogs.com/minconding/p/10458400.html