Vlad5080

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

Feb 21st, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. void Sort(int* mas, int n){
  2.  
  3.     unsigned long int M = 0, C = 0;
  4.  
  5.     for (int j = 1; j < n; j++){
  6.  
  7.         int key = mas[j];
  8.         int chetchik = 0;
  9.         int i = j - 1;
  10.  
  11.         C++;
  12.  
  13.         while (i >= 0 && mas[i] > key){
  14.  
  15.             mas[i + 1] = mas[i];
  16.  
  17.             i--;
  18.  
  19.             C++;
  20.  
  21.             M++;
  22.  
  23.             chetchik++;
  24.         }
  25.  
  26.         mas[i + 1] = key;
  27.     }
  28.  
  29.     if (n != 10) cout << "C = " << C << " M = " << M << "\n";
  30.  
  31. }
Add Comment
Please, Sign In to add comment