shell sort - c programwrite a program to define


Shell sort - C Program:

Write a program to define shell sort.

void main()

{                  //program for sorting by select sort

int a[20],i,k,j,n;

 

clrscr();

 

printf("How many nos are to be sorted\n");

scanf("%d",&n);

 

for (i=0;i<=n-1;i++)

{

printf("Enter the value of %d no\t",i+1);

scanf("%d",&a[i]);

}

printf("Make sure !Are your values read correctly?\n");

 

for (i=0;i<=n-1;i++)

printf("%d \n",a[i]);

 

for (i=0;i<=n-1;i++)   //In select sort we consider the 1 st element &

for (j=i+1;j<=n-1;j++) //compare it with the remaining in the 1st step

   {                   //&swaping is done next considering 2nd element etc.

     if (a[i] >= a[j])

      {

                k=a[i];

                a[i]=a[j];

                a[j]=k;

       }

   }

 

printf("The sorted data is\n");

                for (j=0;j<=n -1;j++)

                printf("%d\n",a[j]);

getch();

}

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: shell sort - c programwrite a program to define
Reference No:- TGS0174870

Expected delivery within 24 Hours