#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <time.h>
#define FCTR 8
void odd_even_merge( unsigned int * d, int n, int skip) {
int idx, tmp;
if ( n > 2 ) {
odd_even_merge( d, n / 2 , skip * 2 ) ;
odd_even_merge( d + skip, n / 2 , skip * 2 ) ;
for ( idx = 1 ; idx <= n - 3 ; idx += 2 ) {
if ( d[ idx * skip] > d[ ( idx + 1 ) * skip] ) {
tmp= d[ idx * skip] ;
d[ idx * skip] = d[ ( idx + 1 ) * skip] ;
d[ ( idx + 1 ) * skip] = tmp; }
}
}
else {
if ( d[ 0 ] > d[ skip] ) {
tmp= d[ 0 ] ;
d[ 0 ] = d[ skip] ;
d[ skip] = tmp;
}
}
}
void odd_even_mergesort( unsigned int * d/, int n) {
if ( n > 1 ) {
odd_even_mergesort( d, n / 2 ) ;
odd_even_mergesort( d + n / 2 , n / 2 ) ;
odd_even_merge( d, n, 1 ) ;
}
}
int main( void ) {
unsigned int * data;
unsigned int elementSize = FCTR, counter;
data
= ( unsigned int * ) malloc ( sizeof ( unsigned int ) * elementSize
) ; for ( counter = 0 ; counter < elementSize ; counter++ ) {
data
[ counter
] = ( unsigned int ) ( ( rand ( ) / ( ( double ) RAND_MAX
+ 1.0f ) ) * INT_MAX
) ; }
for ( counter
= 0 ; counter
< elementSize
; counter
++ ) { printf ( "(%d)\n " , data
[ counter
] ) ; } odd_even_mergesort( data, elementSize) ;
for ( counter
= 0 ; counter
< elementSize
; counter
++ ) { printf ( "(%d)\n " , data
[ counter
] ) ; }
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYWxsb2MuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8dGltZS5oPgoKI2RlZmluZSBGQ1RSIDgKCnZvaWQgb2RkX2V2ZW5fbWVyZ2UodW5zaWduZWQgaW50KiBkLCBpbnQgbiwgaW50IHNraXApIHsKICBpbnQgaWR4LHRtcDsKICBpZiAobiA+IDIpewogICAgb2Rk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CX0KCgkJZm9yIChjb3VudGVyID0gMCA7IGNvdW50ZXIgPCBlbGVtZW50U2l6ZSA7IGNvdW50ZXIrKyApe3ByaW50ZigiKCVkKVxuIixkYXRhW2NvdW50ZXJdKTt9CgkJcHJpbnRmKCJcbiIpOwoJCW9kZF9ldmVuX21lcmdlc29ydChkYXRhLCBlbGVtZW50U2l6ZSk7CgkJcHJpbnRmKCJcbiIpOwoJCWZvciAoY291bnRlciA9IDAgOyBjb3VudGVyIDwgZWxlbWVudFNpemUgOyBjb3VudGVyKysgKXtwcmludGYoIiglZClcbiIsZGF0YVtjb3VudGVyXSk7fQoKCQlmcmVlKGRhdGEpOwp9
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