// // Created by tangs on 2018/11/18. // #include using namespace std; void SelectSort(int A[], int n) { int i, j, min; for (i = 0; i < n - 1; i++) { min = i; for (j = i + 1; j < n; j++) if (A[j] < A[min]) min = j; if (min != i) swap(A[i], A[min]); } } int main() { int A1[] = {6, 1, 5, 2, 1, 9, 10, 24, 7, 0}; SelectSort(A1, 10); // print: // 0 1 1 2 5 6 7 9 10 24 for (int i = 0; i < 10; i++) { cout << A1[i] << " "; } cout << endl; return 0; }