Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. using namespace std;
  5.  
  6. void pisz(int t[], int n) {
  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. int licz = 0;
  20. for (int j = 1; j < k; j++)
  21. if (tab[j-1] > tab[j]) swap(tab[j-1], tab[j]), licz++;
  22. if (licz == 0) break;
  23. pisz(tab, n);
  24. }
  25. return 0;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement