main.cpp 578 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // Created by tangs on 2018/11/18.
  3. //
  4. #include <iostream>
  5. using namespace std;
  6. void SelectSort(int A[], int n) {
  7. int i, j, min;
  8. for (i = 0; i < n - 1; i++) {
  9. min = i;
  10. for (j = i + 1; j < n; j++)
  11. if (A[j] < A[min])
  12. min = j;
  13. if (min != i)
  14. swap(A[i], A[min]);
  15. }
  16. }
  17. int main() {
  18. int A1[] = {6, 1, 5, 2, 1, 9, 10, 24, 7, 0};
  19. SelectSort(A1, 10);
  20. // print:
  21. // 0 1 1 2 5 6 7 9 10 24
  22. for (int i = 0; i < 10; i++) {
  23. cout << A1[i] << " ";
  24. }
  25. cout << endl;
  26. return 0;
  27. }