Advertisement
danny-iv

bubblesort

Nov 20th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     size_t n;
  6.     cout << "Vyvedi razmera na masiva: ";
  7.     cin >> n;
  8.     int*array = new int[n];
  9.  
  10.     int num[];
  11.     for (int i = 0; i < n; i++){
  12.         cout << "Vyvedi elementi [" << i << "]=";
  13.         cin >> num[i];
  14.     }
  15.     cout << "\n Masivyt sled sortirane:\n |  ";
  16.     for (int temp, i = 0; i < n-1; i++){
  17.         for (int j = i+1; j < n ; j++){
  18.             if (num[i]>num[j]){
  19.                 temp = num[i];
  20.                 num[i] = num[j];
  21.                 num[j] = temp;
  22.             }
  23.         }
  24.     }
  25.     for (int i = 0; i < n; i++){
  26.         cout << num[i] << " | ";
  27.     }
  28.     cout << endl;
  29.     delete[] array;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement