fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int>selectionSort(vector<int>&a){
  5. int n = a.size();
  6. for(int i =0 ;i < n ;i++){
  7. int minInd=i;
  8. for(int j = i+1 ; j< n ;j++){
  9. if(a[minInd]>a[j]){
  10. minInd = j;
  11. }
  12. }
  13. if(minInd!= i){
  14. swap(a[minInd],a[i]);
  15. }
  16. }
  17. return a;
  18. }
  19. int main() {
  20. int n;cin>>n;
  21.  
  22. vector<int>a(n);
  23. for(int i = 0;i<n ;i++){
  24. cin>>a[i];
  25. }
  26.  
  27. vector<int>ans = selectionSort(a);
  28. for(int &x:ans)cout<<x<<endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 5320KB
stdin
6
1 6 4 9 3 4
stdout
1
3
4
4
6
9