shell sort
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code:
#include<stdio.h>
#include<conio.h>
int arr[30],i,j,k,tmp,num;
void shellsort()
{
for(i=num/2; i>0; i=i/2)
for(j=i; j<num; 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;
}
}
int main()
{
printf("Enter total no. of elements : ");
scanf("%d", &num);
for(k=0; k<num; k++)
{
printf("\nEnter %d number : ",k+1);
scanf("%d",&arr[k]);
}
shellsort();
printf("After Shell Sort\n");
for(k=0; k<num; k++)
printf("%d\t",arr[k]);
getch();
return 0;
}
output:-Enter total no. of elements : 5 Enter 1 number : 29 Enter 2 number : 21 Enter 3 number : 64 Enter 4 number : 02 Enter 5 number : 56 After Shell Sort 2 21 29 56 64
--->shell sort program with no of pass ,count and time complexity

0 comments: