From bb83830fcc68a92002fe686b2f2fd082319181e0 Mon Sep 17 00:00:00 2001 From: Sarthak khare <44430266+Roaster96@users.noreply.github.com> Date: Fri, 2 Oct 2020 23:55:10 +0530 Subject: [PATCH] Shell Sort using C++ --- Shell_Sort | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Shell_Sort diff --git a/Shell_Sort b/Shell_Sort new file mode 100644 index 0000000..13642b5 --- /dev/null +++ b/Shell_Sort @@ -0,0 +1,41 @@ +#include +#include +void swap(int *x,int *y) +{ + int temp=*x; + *x=*y; + *y=temp; +} +void ShellSort(int A[],int n) +{ + int gap,i,j,temp; + + for(gap=n/2;gap>=1;gap/=2) + { + for(i=gap;i=0 && A[j]>temp) + { + A[j+gap]=A[j]; + j=j-gap; + } + A[j+gap]=temp; + + } + } + +} +int main() +{ + int A[]={11,13,7,12,16,9,24,5,10,3},n=10,i; + + SellSort(A,n); + + for(i=0;i<10;i++) + printf("%d ",A[i]); + printf("\n"); + + return 0; +}