SHELL SORT implementation in C++
/********************************/ /*PROGRAM TO PERFORM SHELL SORT*/ /********************************/
#include < stdio.h> #include < conio.h>
void main() { int a[10],n,i,j,temp,gap,swap; clrscr(); printf("Enter the size of a: "); scanf("%d",&n); printf("\nEnter the elements of a:\n"); for(i=0;i { scanf("%d",&a[i]); } gap=n/2; while(gap>=1) { do { swap=0; for(j=0;j<(n-gap);j++) { if(a[j]>a[j+gap]) { temp=a[j]; a[j]=a[j+gap]; a[j+gap]=temp; swap=1; } } }while(swap==1); gap=gap/2; } printf("\nSorted elements are:\n"); for(i=0;i { printf("%4d",a[i]); } getch(); }
http://
http://
Contributed by:
Rohit kakria
I am software developer
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=339
Click here to go on website
|