0% found this document useful (0 votes)
7 views3 pages

Shell Sort Implementation in C

This C program implements a shell sort algorithm to sort an integer array. The shellsort function takes the array and its size as parameters. It sorts the array using increments of size n/2, n/4, etc. until the increment reaches 1. At each increment size, it compares adjacent elements and swaps them if out of order. The main function gets array size and elements from user, calls shellsort, and prints the sorted array.

Uploaded by

maman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Shell Sort Implementation in C

This C program implements a shell sort algorithm to sort an integer array. The shellsort function takes the array and its size as parameters. It sorts the array using increments of size n/2, n/4, etc. until the increment reaches 1. At each increment size, it compares adjacent elements and swaps them if out of order. The main function gets array size and elements from user, calls shellsort, and prints the sorted array.

Uploaded by

maman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 12: PROGRAM TO PERFORM SHELL SORT

August 19, 2019 ON ARRAY IN C

#include<stdio.h>
#include<conio.h>
void shellsort(int a[],int num);
void shellsort(int a[],int num)
{ int i,j,k,temp;
for(i=num/2;i>0;i=i/2)
{ for(j=i;j<num;j++)
{
for(k=j-1;k>=0;k=k-i)
{ if(a[k+i]>=a[k])
break;
else
{ temp=a[k];
a[k]=a[k+i];
a[k+i]=temp;
}
}
}
Vrinda Sharma Signature
18CE063
PROGRAM 12: PROGRAM TO PERFORM SHELL SORT
August 19, 2019 ON ARRAY IN C

}
}
void main()
{ clrscr();
int a[50],i,num;
printf("\nEnter size of array:");
scanf("%d",&num);
printf("\nEnter elements of array:\n");
for(i=0;i<num;i++)
scanf("%d",&a[i]);
shellsort(a,num);
printf("\nArray after shell short:\n");
for(i=0;i<num;i++)
printf("%d\n",a[i]);
getch();
}

Vrinda Sharma Signature


18CE063
PROGRAM 12: PROGRAM TO PERFORM SHELL SORT
August 19, 2019 ON ARRAY IN C

OUTPUT:

Vrinda Sharma Signature


18CE063

You might also like