Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // bubble
  4. //
  5. // Created by Dominik Smaga on 10/12/2016.
  6. // Copyright © 2016 Dominik Smaga. All rights reserved.
  7. //
  8. #include <cstdio>
  9. #include <iostream>
  10. using namespace std;
  11.  
  12.  
  13. int main() {
  14. int n , i, j, k;
  15.  
  16. cout << "podaj wielkosc tablicy" << endl;
  17.  
  18. cin >> n;
  19. int *tab = new int[n];
  20.  
  21. cout << "podaj elementy tablicy oddzielone spacją" << endl;
  22.  
  23. //pobiera wszytkie elementy tablicy wpisane przez użytkownika z pominięciem spacji
  24. for(i=0;i<n;i++){
  25. cin >> tab[i];
  26. }
  27.  
  28.  
  29. //wypisanie elentow tabliny nieposortowanych
  30. cout << "Elementy nieposortowane:";
  31. for (j=0; j<i; j++)
  32. {
  33. cout << tab[j];
  34. if (j < n-1) cout << ",";
  35. }
  36. cout << "\n";
  37. // wykonanie sortowanie buble -----------------------------------
  38.  
  39. do {
  40. for (k=0;k<n-1;k++)
  41. if (tab[k] > tab[k+1]) {
  42. swap(tab[k], tab[k+1]);
  43. }
  44. n=n-1;
  45.  
  46. } while (n>1);
  47.  
  48.  
  49. //wypisanie elentow posortownych
  50.  
  51. cout << "Elemnety posortowane:";
  52. j=0;
  53. for (j=0; j<i; j++)
  54. {
  55. cout << tab[j];
  56. if (j < i-1) cout << ",";
  57. }
  58. cout << "\n";
  59.  
  60. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement