Advertisement
Neveles

© 2020 Neveles. All rights reserved.

Apr 13th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. void ShellSort(int n, int *arr, int &counter)
  2. {
  3.   int i, j, step;
  4.   int tmp;
  5.   for (step = n / 2; step > 0; step /= 2)
  6.   {
  7.     for (i = step; i < n; i++)
  8.     {
  9.       tmp = arr[i];
  10.       for (j = i; j >= step; j -= step)
  11.       {
  12.         ++counter;
  13.         if (tmp < arr[j - step])
  14.         {
  15.           arr[j] = arr[j - step];
  16.         }
  17.         else
  18.         {
  19.           break;
  20.         }
  21.       }
  22.       arr[j] = tmp;
  23.     }
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement