Your Ad Here

Wednesday, February 27, 2008

Shell Sort

#include< stdio.h>
#include< conio.h>

void shellsort(int a[],int n)
{
int j,i,k,m,mid;
for(m = n/2;m>0;m/=2)
{
for(j = m;j< n;j++)
{
for(i=j-m;i>=0;i-=m)
{
if(a[i+m]>=a[i])
break;
else
{
mid = a[i];
a[i] = a[i+m];
a[i+m] = mid;
}
}
}
}
}

main()
{
int a[10],i,n;
clrscr();

printf("Enter The number Of Elements\t: ");
scanf("%d",&n);
for(i=0;i< n;i++)
{
printf("\nElement %d\t: ",i+1);
scanf("%d",&a[i]);
}

printf("\nArray Befor Sorting : ");
for(i=0;i< n;i++)
printf("%5d",a[i]);
shellsort(a,n);

printf("\nArray After Sorting : ");
for(i=0;i< n;i++)
printf("%5d",a[i]);
getch();
return 0;
}

/* OUTPUT

Enter The number Of Elements : 5

Element 1 : 21

Element 2 : 36

Element 3 : 54

Element 4 : 2

Element 5 : 0

Array Befor Sorting : 21 36 54 2 0
Array After Sorting : 0 2 21 36 54
*/

11 comments:

Anonymous said...

can u give me explanation???

Unknown said...

thank you for the program.....i used it in my presentation...God Bless...

Unknown said...

thank you for the program.....i used it in my presentation...God Bless...

Anonymous said...

domo....

ur program saved the life of humanity...

;'p joke..

Anonymous said...

Thanks for the programs. I got several ideas for my assignments ^_^.

Anonymous said...

Damn, rather interesting topic. Where will I find that subscription?

Sara Trider
rf sweep

Anonymous said...

WOW man, you just save the life of this little student, thanks a lot, you sir deserve 5 cookies and 10 internetz!!

Thast a lot man.

Anonymous said...

this seems to be bubble sort logic

Anonymous said...

hey man, ur program is really helpful.used it in my assignment....God bless you man

Anonymous said...

you made binary search concept , binary sort.

Anonymous said...

Hey progrmmmr for cpp we can replace printf and scanf wit cout n cin ?

Your Ad Here