fork download
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. #define FCTR 8
  7.  
  8. void odd_even_merge(unsigned int* d, int n, int skip) {
  9. int idx,tmp;
  10. if (n > 2){
  11. odd_even_merge(d, n / 2, skip * 2);
  12. odd_even_merge(d + skip, n / 2, skip * 2);
  13. for(idx = 1; idx <= n - 3; idx += 2) {
  14. if (d[idx * skip] > d[(idx + 1) * skip]) {
  15. tmp=d[idx * skip];
  16. d[idx * skip]=d[(idx + 1) * skip];
  17. d[(idx + 1) * skip]=tmp;}
  18. }
  19. }
  20. else{
  21. if (d[0] > d[skip]){
  22. tmp=d[0];
  23. d[0]=d[skip];
  24. d[skip]=tmp;
  25. }
  26. }
  27. }
  28.  
  29. void odd_even_mergesort(unsigned int* d/, int n) {
  30. if (n > 1) {
  31. odd_even_mergesort(d, n / 2);
  32. odd_even_mergesort(d + n / 2, n / 2);
  33. odd_even_merge(d, n, 1);
  34. }
  35.  
  36. }
  37. int main(void) {
  38. unsigned int* data;
  39. unsigned int elementSize = FCTR,counter;
  40.  
  41. data = (unsigned int*)malloc(sizeof(unsigned int) * elementSize);
  42. for (counter = 0 ; counter < elementSize ; counter++ ){
  43. data[counter] = (unsigned int)((rand() / ((double)RAND_MAX+1.0f))* INT_MAX);
  44. }
  45.  
  46. for (counter = 0 ; counter < elementSize ; counter++ ){printf("(%d)\n",data[counter]);}
  47. printf("\n");
  48. odd_even_mergesort(data, elementSize);
  49. printf("\n");
  50. for (counter = 0 ; counter < elementSize ; counter++ ){printf("(%d)\n",data[counter]);}
  51.  
  52. free(data);
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:29:40: error: expected ‘;’, ‘,’ or ‘)’ before ‘/’ token
 void odd_even_mergesort(unsigned int* d/, int n) {
                                        ^
prog.c: In function ‘main’:
prog.c:43:71: error: ‘INT_MAX’ undeclared (first use in this function)
    data[counter] = (unsigned int)((rand() / ((double)RAND_MAX+1.0f))* INT_MAX);
                                                                       ^
prog.c:43:71: note: each undeclared identifier is reported only once for each function it appears in
prog.c:48:3: warning: implicit declaration of function ‘odd_even_mergesort’ [-Wimplicit-function-declaration]
   odd_even_mergesort(data, elementSize);
   ^
prog.c:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty