fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void selectionSort(int arr[], int n) {
  5. for (int i = 0; i < n - 1; i++) {
  6. int minIdx = i;
  7. for (int j = i + 1; j < n; j++) {
  8. if (arr[j] < arr[minIdx])
  9. minIdx = j;
  10. }
  11. swap(arr[i], arr[minIdx]);
  12. }
  13. }
  14.  
  15. int main() {
  16. int arr[] = {64, 25, 12, 22, 11};
  17. int n = sizeof(arr) / sizeof(arr[0]);
  18. selectionSort(arr, n);
  19.  
  20. for (int i = 0; i < n; i++)
  21. cout << arr[i] << " ";
  22. cout << endl;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
11 12 22 25 64