选择排序的实现方法

 1 public class SelectSortDemo {
3 /**
4 * @param args
5 * 选择排序 抗压性
6 */
7 public static void main(String[] args) {
8 // TODO Auto-generated method stub
9 int[] ary = { 8, 3, 5, 1, 4, 2, 7 };
10 ary = selectSort(ary);
11 for (int i = 0; i < ary.length; i++) {
12 System.out.print(ary[i] + " ");
13 }
14 }
15
16 public static int[] selectSort(int[] ary) {
17 for (int i = 0; i < ary.length; i++) {
18 for (int j = i + 1; j < ary.length; j++) {
19 if (ary[j] < ary[i]) {
20 int temp = ary[j];
21 ary[j] = ary[i];
22 ary[i] = temp;
23 }
24 }
25 }
26 return ary;
27 }
28 }

  

原文地址:https://www.cnblogs.com/superjt/p/2116989.html