Advertisement
hurmawe

Сортировка вставками

Dec 18th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int dlina_massiva;
  8.  
  9.     cin >> dlina_massiva;
  10.     vector<int> array(dlina_massiva);
  11.  
  12.     for (auto& x : array)
  13.     {
  14.         cin >> x;
  15.     }
  16.  
  17.     for (int i = 1; i < dlina_massiva; i++)
  18.     {
  19.         for (int j = 0; j < i; j++)
  20.         {
  21.             if (array[j] > array[i])
  22.                 swap(array[j], array[i]);
  23.         }
  24.     }
  25.  
  26.     for (auto& x : array)
  27.     {
  28.         cout << x << " ";
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement