Advertisement
patryk

Untitled

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