Advertisement
patryk

Untitled

Mar 17th, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<time.h>
  4.  
  5. int N, i, t, j, k, s, x, m, h[4];
  6.  
  7. void shellsort(int a[]){
  8.  
  9.     h[0] = 9;
  10.     h[1] = 5;
  11.     h[2] = 3;
  12.     h[3] = 1;
  13.     for(m=0; m<4; m++){
  14.         k = h[m];
  15.         s = -k;
  16.         for(i=k+1; i<N; i++){
  17.             x = a[i];
  18.             j = i-k;
  19.             if(s==0) s=-k;
  20.             s = s+1;
  21.             a[s] = x;
  22.             while(x < a[j]){
  23.                 a[j+k] = a[j];
  24.                 j = j-k;
  25.             }
  26.             a[j+k] = x;
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. int main(){
  33.     N = 100;
  34.     int a[N];
  35.  
  36.     srand(time(NULL));
  37.     for(i=0; i<N; i++) a[i] = rand();
  38.  
  39.     shellsort(a);
  40.  
  41.     for(i=0; i<N; i++) printf("[%d]: %d\t", i, a[i]);
  42.     getch();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement