Skip to content

Instantly share code, notes, and snippets.

@setanjan123
Created October 31, 2017 15:00
Show Gist options
  • Save setanjan123/c8c06b96cce7d2d6e9814d5b223e15d1 to your computer and use it in GitHub Desktop.
Save setanjan123/c8c06b96cce7d2d6e9814d5b223e15d1 to your computer and use it in GitHub Desktop.
#include<stdio.h>
void shellsort(int *arr,int n)
{
int gap,j,temp,i;
gap=n/2;
while(gap>0)
{
i=0;
j=gap;
while(j<n)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
if((j%gap==0)&&(i%gap==0))
{
if(arr[i]<arr[0])
{
temp=arr[i];
arr[i]=arr[0];
arr[0]=temp;
}
}
}
i++;
j++;
}
gap=gap/2;
}
}
int main()
{
int n,i;
void *arr,
printf("Enter the size of the array\n");
scanf("%d",&n);
arr=malloc(sizeof(int)*n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
shellsort(arr,n);
for(i=0;i<n;i++)
printf("%d\t",arr[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment