#include <stdio.h> #include <stdlib.h> #include <time.h> // arguments int limit, int windowShift int getRandomNumber(int limit, int windowShifter){ return ( rand() % limit ) + windowShifter; } // Should be done in parallel. void OddEvenSort(int *array, int size){ int i; // Even Sort for(i = 0; i < size - 1; i+=2){ if(array[i] > array[i+1]){ int temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } } // Odd Sort for(i = 1; i < size - 1; i+=2){ if(array[i] > array[i+1]){ int temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } } } int main(){ time_t t; srand( (unsigned) time(&t) ); int i; int *array; int size = 10; // Allocate memory space for array. array = (int *) malloc (size * sizeof(int)); // Generate random numbers. int *pointer = array; for(i = 0; i < size; i++, pointer++){ *pointer = getRandomNumber(100, 1); } // Print the random array. pointer = array; for(i = 0; i < size; i++, pointer++){ printf("%d ", *pointer); } printf("\n"); for(i = 0; i < size/2 - 1; i++){ OddEvenSort(array, size); } // Print the random array. pointer = array; for(i = 0; i < size; i++, pointer++){ printf("%d ", *pointer); } free(array); }