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