选择排序(java版)

public class SelectSort {
 
 public static void selectSort(int a[]){
  int temp;
  /**
   * 采用选择法对数组a排序
   */
  for (int i = 0; i < a.length-1; i++) {
   for (int j = i + 1; j < a.length; j++) {
    if (a[i] > a[j]) {
     temp = a[i];
     a[i] = a[j];
     a[j] = temp;
    }
   }
  }
 }
 public static void main(String[] args) {
  int a[] = { 2, 4, 1, 6, 7 };
        //调用排序方法
  selectSort(a);
  /**
   * 遍历数组a
   */
  for(int i=0;i<a.length;i++){
   System.out.print(a[i]+" ");
  }
 }
}

原文地址:https://www.cnblogs.com/zhanggaosong/p/2955035.html