diff --git a/Sorting/shellsort b/Sorting/shellsort new file mode 100644 index 0000000..dd19713 --- /dev/null +++ b/Sorting/shellsort @@ -0,0 +1,43 @@ +// C++ implementation of Shell Sort +#include +using namespace std; + + +int shellSort(int arr[], int n) +{ + // Start with a big gap, then reduce the gap + for (int gap = n/2; gap > 0; gap /= 2) + { + for (int i = gap; i < n; i += 1) + { + int temp = arr[i]; + int j; + for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) + arr[j] = arr[j - gap]; + arr[j] = temp; + } + } + return 0; +} + +void printArray(int arr[], int n) +{ + for (int i=0; i