From b8e73c0d9c97007bdecdfebfb754f30a3e5b94fa Mon Sep 17 00:00:00 2001 From: Varun2012 Date: Thu, 1 Oct 2020 14:29:51 +0530 Subject: [PATCH] Create shell sort --- com/williamfiset/datastructures/shell sort | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 com/williamfiset/datastructures/shell sort diff --git a/com/williamfiset/datastructures/shell sort b/com/williamfiset/datastructures/shell sort new file mode 100644 index 0000000..5f43b0a --- /dev/null +++ b/com/williamfiset/datastructures/shell sort @@ -0,0 +1,31 @@ +#include +void main() +{ +int arr[10]={-1}; + int i, j, n, flag = 1, gap_size, temp; + printf("\n Enter the number of elements in the array: "); + scanf("%d", &n); + printf("\n Enter %d numbers: ",n); // n was added + for(i=0;i 1) +{ + flag = 0; + gap_size = (gap_size + 1) / 2; + for(i=0; i< (n - gap_size); i++) + { + if( arr[i+gap_size] < arr[i]) + { + temp = arr[i+gap_size]; + arr[i+gap_size] = arr[i]; + arr[i] = temp; + flag = 0; + } + } +} + printf("\n The sorted array is: \n"); + for(i=0;i