Advertisement
Guest User

shell

a guest
Feb 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. //============================================================================
  2. // Name        : shell-sort.cpp
  3. // Author      :
  4. // Date        :
  5. // Copyright   :
  6. // Description : Implementation of shell sort in C++
  7. //============================================================================
  8.  
  9. #include "sort.h"
  10. #include <iostream>
  11.  
  12. vector<int>
  13. ShellSort::sort(vector<int>& A, int size)
  14. {
  15.   for (int gap = size/2; gap > 0; gap /= 2) {
  16.     for (int i = gap; i < size; i += 1) {
  17.            int temp = A[i];
  18.            int j;            
  19.            for (j = i; j >= gap && A[j - gap] > temp; j -= gap)
  20.                A[j] = A[j - gap]; num_cmps++;
  21.            A[j] = temp;
  22.        }
  23.   }
  24. return A;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement