#include<stdio.h>
#include<conio.h>
int array[5];
void ShellSort(int *array, int n)
{
int i,j,iter, jter, increment, temp;
for(increment = n/2;increment > 0; increment /= 2)
{
 for(i = increment; i<n; i++)
 {
 temp = array[i];
 for(j = i; j >= increment ;j-=increment)
 {
 if(temp < array[j-increment])
 {
 array[j] = array[j-increment];
 }
 else
 {
 break;
 }
 }
 array[j] = temp;
 }
 }
}

int main()
{
 int n, iter;
 printf("Enter The Total Number Of Array Elements : ");
 scanf("%d",&n);
 
 for(iter = 0;iter < n;iter++)
 {
 printf("Enter the Element : ");
 scanf("%d",&array[iter]);
 }
 /* Calling this functions sorts the array */
 ShellSort(array,n);
 printf("After Shell Sorting : \n");
 for(iter = 0;iter < n;iter++)
 {
 printf("%d ",array[iter]);
 }
 printf("\n");
 getch();
 return 0;
}
OUTPUT
Enter The Total Number Of Array Elements : 5

Enter element : 40 
Enter element : 10 
Enter element : 30 
Enter element : 60 
Enter element : 20 

After Shell Sorting :
 10
 20
 30
 40
 60

Leave a Reply

Subscribe to Posts | Subscribe to Comments

All Notes on BCA

All Notes  on BCA
BCA all subjects notes

Total Pageviews

Translate

Powered by Blogger.

Copyright © All Notes on BCA