Advertisement
Eksekk

Sort

May 20th, 2021
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. void sortowanieBabelkowe(std::vector<std::string>& vec)
  6. {
  7.     for (int i = vec.size() - 1; i >= 0; --i)
  8.     {
  9.         bool zmiana = false;
  10.         for (int j = 0; j < i; ++j)
  11.         {
  12.             if (vec[j] > vec[j + 1])
  13.             {
  14.                 std::swap(vec[j], vec[j + 1]);
  15.                 zmiana = true;
  16.             }
  17.         }
  18.         if (!zmiana)
  19.         {
  20.             break;
  21.         }
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     std::vector<std::string> vec;
  28.     std::string str;
  29.     while (std::cin >> str)
  30.     {
  31.         vec.push_back(str);
  32.     }
  33.     sortowanieBabelkowe(vec);
  34.     for (int i = 0; i < vec.size(); ++i)
  35.     {
  36.         std::cout << vec[i] << ' ';
  37.     }
  38.     std::cout << '\n';
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement