Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void HibbardSort(int n, int *arr) //SHELL SORT - HIBBARD'S INCREMENTS
- {
- int i, j, k, increment, temp;
- int swp = 0, comp = 0;
- double val;
- val = (int)log(n + 1) / log(2);
- increment = (int)pow(2, val) - 1;
- while (increment > 0)
- {
- for (i = 0;i < increment;i++)
- {
- for (j = 0;j < n;j += increment)
- {
- temp = arr[j];
- for (k = j - increment;k >= 0 && temp < arr[k];k -= increment)
- {
- comp++;
- swp++;
- arr[k + increment] = arr[k];
- }
- arr[k + increment] = temp;
- swp++;
- }
- }
- comp++;
- val--;
- if (increment != 1)
- {
- increment = pow(2, val) - 1;
- }
- else
- {
- increment = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement