SHELL SORT implementation in C++
|
Download Attachment
|
/********************************/ /*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(); }
|
|
|
|
|
Share this article
| Print |
Article read by 2943 times
|
|
|