Advertisement
patryk

Untitled

Mar 18th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 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];
  19. j = i-k;
  20. if(s==0) s = -k;
  21. s = s+1;
  22. a[s] = x;
  23. while(x < a[j]){
  24. a[j+k] = a[j];
  25. j = j-k;
  26. }
  27. a[j+k] = x;
  28. }
  29. }
  30. }
  31.  
  32.  
  33. int main(){
  34. N = 1000;
  35. int a[N];
  36.  
  37. srand(time(NULL));
  38. for(i=0; i<N; i++) a[i] = rand();
  39.  
  40. shellsort(a);
  41.  
  42. for(i=0; i<N; i++) printf("[%d]: %d\t", i, a[i]);
  43. getch();
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement