Advertisement
MrPoxipol

Buble sort

Mar 4th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int tab[] = {3, 2, 5, 6, 1, 12, 15, 675, 23, 9}; // 10
  8.     const size_t SIZE = 10;
  9.  
  10.     cout << "Lista przed posortowaniem:" << endl;
  11.     for (int i: tab)
  12.         cout << i << " ";
  13.  
  14.     cout << endl;
  15.  
  16.     for (int i = 0; i < SIZE; ++i)
  17.     {
  18.         for (int j = 0; j < SIZE-i-1; ++j)
  19.         {
  20.             if(tab[j] > tab[j+1])
  21.             {
  22.                 int temp = tab[j+1];
  23.                 tab[j+1] = tab[j];
  24.                 tab[j] = temp;
  25.             }
  26.         }
  27.     }
  28.  
  29.     cout << "Lista po posortowaniu: " << endl;
  30.     for (int i: tab)
  31.         cout << i << " ";
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement