Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9.  
  10. int a[n];
  11. for(int i=0;i<n;i++)
  12. cin>>a[i];
  13.  
  14. for (int i = 1; i < n; ++i) {
  15. int j = i;
  16. while(j && a[j - 1] > a[j]) {
  17. swap(a[j - 1], a[j]);
  18. --j;
  19. }
  20. if (j != i){
  21. for(int i=0;i<n;i++)
  22. cout << a[i] << " ";
  23. cout <<"\n";
  24. }
  25. }
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement