Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. void pisz(int t[], int n)
  6. {
  7. for (int i = 0; i < n; i++)
  8. cout << t[i] << ' ';
  9. cout << endl;
  10. }
  11.  
  12. int main(){
  13. int n;
  14. cin >> n;
  15. int tab[n];
  16. for (int &x: tab) cin >> x;
  17.  
  18. for(int k = n; k >= 2; k--)
  19. {
  20. int licz = 0;
  21. for(int j = 1; j < k; j++)
  22. {
  23. if(tab[j-1] > tab[j]) swap(tab[j -1], tab[j]), licz++;
  24. }
  25. if (licz == 0)
  26. {
  27. break;
  28. }
  29. pisz(tab,n);
  30. }
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement