From 6dc25b54473fdec57f5a78808b815452a20ab778 Mon Sep 17 00:00:00 2001 From: SAKSHI <73335454+sam260@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:58:10 +0530 Subject: [PATCH] Create shellsort --- Sorting/shellsort | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Sorting/shellsort 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