/*
Shell Sort Algorithm
Created By: Pirate
*/
Shell Sort Algorithm
Created By: Pirate
*/
#include<stdio.h>
#include<conio.h>
int arr[100];
void shell_sort(int n);
int main()
{
int
i,n;
printf("***
SHELL SORT ***\n");
printf("Enter
the no. of elements : ");
scanf("%d",
&n);
printf("Enter %d
elements:\n",n);
for(i=0; i<n; i++)
{
scanf("%d",&arr[i]);
}
shell_sort(n);
printf("\n***
After Sorting ***\n");
for(i=0;
i<n; i++)
{
printf("%d\t",arr[i]);
}
getch();
return
0;
}
void shell_sort(int n)
{
int
i,j,k,tmp;
for(i=n/2;
i>0; i=i/2)
{
for(j=i;
j<n; j++)
{
for(k=j-i;
k>=0; k=k-i)
{
if(arr[k+i]>=arr[k])
break;
else
{
tmp=arr[k];
arr[k]=arr[k+i];
arr[k+i]=tmp;
}
}
}
}
}
Output
This comment has been removed by a blog administrator.
ReplyDelete