0% found this document useful (0 votes)
21 views2 pages

29.1 191. Shell Sort PDF

The document describes the Shell Sort algorithm for sorting an array of integers. It includes code to implement the Shell Sort algorithm using gaps to sort the array and swap elements, and provides a main function that tests the algorithm on a sample array.

Uploaded by

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

29.1 191. Shell Sort PDF

The document describes the Shell Sort algorithm for sorting an array of integers. It includes code to implement the Shell Sort algorithm using gaps to sort the array and swap elements, and provides a main function that tests the algorithm on a sample array.

Uploaded by

Shubham Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Shell Sort

#include <stdio.h>
#include<stdlib.h>

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<n;i++)
{
temp=A[i];
j=i-gap;
while(j>=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;
}

You might also like