Advertisement
patryk

Untitled

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