Shell Sort

1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  int c=1, a[10], n;  
4:  void shell();  
5:  void main()  
6:  {  
7:         int i;  
8:         clrscr();  
9:         printf("Enter the number of elements : ");  
10:         scanf("%d", &n);  
11:         printf("\nEnter the elements : \n");  
12:         for(i=0;i<n;i++)  
13:                scanf("%d", &a[i]);  
14:         shell();  
15:         getch();  
16:  }  
17:  void shell()  
18:  {  
19:         int i, j, k, m, mid;  
20:         clrscr();  
21:         for(m=m/2;m>0; m/=2)  
22:         {  
23:                for(j=m; j<n; j++)  
24:                {  
25:                   for(i=j-m; i>=0; i-=m)  
26:                   {  
27:                          if(a[i+m]>=a[i])  
28:                             break;  
29:                    else  
30:                          {  
31:                             mid=a[i];  
32:                             a[i]=a[i+m];  
33:                             a[i+m]=mid;  
34:                          }  
35:                   }  
36:                }  
37:                printf("\n\nAfter Scan %d\n", c);  
38:                for(k=0;k<n;k++)  
39:                   printf("\t%d", a[k]);  
40:                c++;  
41:         }  
42:        printf("\n\n\t\tSORTED ARRAY\n\t");  
43:         for(k=0;k<n;k++)  
44:                printf("%d\t", a[k]);  
45:  }  

No comments:

Post a Comment

Code Of The day - Suggest An Output For The Snippet

  #include<stdio.h>   
  int main()   
  {   
   float a=3.15529;   
   printf("%2.1f\n", a);   
   return 0;   
  }   
· A Code Archive - code1archive