首頁>Club>
5
回覆列表
  • 1 # 使用者6283253387577

    1 public class SelectSort {

    2 public static int[] selectSort(int[] a) {

    3 int n = a.length;

    4 for (int i = 0; i < n - 1; i++) {

    5 int min = i;

    6 for (int j = i + 1; j < n; j++) {

    7 if(a[min] > a[j]) min = j;

    8 }

    9 //交換

    10 int temp = a[i];

    11 a[i] = a[min];

    12 a[min] = temp;

    13 }

    14 return a;

    15 }

    16 }

    性質:1、時間複雜度:O(n2) 2、空間複雜度:O(1) 3、非穩定排序 4、原地排序

  • 中秋節和大豐收的關聯?
  • 古代人掛免戰什麼意思?