fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void selection(int n, int ara[])
  6. {
  7. for(int i = 0; i < n-1; i++) //for selecting the index/position
  8. {
  9. for(int j = i+1; j < n; j++) // pointer for checking forward
  10. {
  11. if(ara[i] > ara[j]) //ara[i] is the picked positioned value {
  12. {
  13. swap(ara[i], ara[j]);
  14. }
  15. for(int i = 0; i < n; i++)
  16. {
  17. cout<<ara[i]<<" ";
  18. }
  19. cout<<endl;
  20. }
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int n;
  27. cin>>n;
  28. int ara[n];
  29. for(int i = 0; i < n; i++)
  30. {
  31. cin>>ara[i];
  32. }
  33.  
  34. selection(n, ara);
  35.  
  36. // for(int i = 0; i < n; i++)
  37. // {
  38. // cout<<ara[i]<<" ";
  39. // }
  40.  
  41. }
  42.  
  43.  
Success #stdin #stdout 0.01s 5328KB
stdin
6
5 8 6 1 7 9
stdout
5 8 6 1 7 9 
5 8 6 1 7 9 
1 8 6 5 7 9 
1 8 6 5 7 9 
1 8 6 5 7 9 
1 6 8 5 7 9 
1 5 8 6 7 9 
1 5 8 6 7 9 
1 5 8 6 7 9 
1 5 6 8 7 9 
1 5 6 8 7 9 
1 5 6 8 7 9 
1 5 6 7 8 9 
1 5 6 7 8 9 
1 5 6 7 8 9