Vlad5080

shell

Mar 25th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. void Shell(int A[], int n) //сортировка Шелла
  2. {
  3. unsigned int C = 0, M = 0;
  4. int d = n, count = 0, j = 0;
  5. d = d / 2;
  6. while (d > 0)
  7. {
  8. for (int i = 0; i < n - d; i++)
  9. {
  10. j = i;
  11. C++;
  12. while (j >= 0 && A[j] > A[j + d])
  13. {
  14. count = A[j];
  15. A[j] = A[j + d];
  16. A[j + d] = count;
  17. j--;
  18. M++;
  19.  
  20. }
  21. }
  22. d = d / 2;
  23. }
  24. if (n != 10) cout << "C = " << C << " M = " << M << "\n";//вывод результатов перестановок
  25. }
Advertisement
Add Comment
Please, Sign In to add comment