/* * Program to test sort function: * Generate a random sequence of N integers, sort them, and check * that the sort succeeded. (N is hardcoded for now, and the sort * function doesn't do anything, so will almost surely fail!) */ #include #include #define N 100 /* function declarations */ void fill_with_random(int nums[], int size); void sort(int nums[], int size); void sort_check(int nums[], int size); /* * main program */ int main(void) { int nums[N]; /* printf("largest random value is %d\n", RAND_MAX); */ fill_with_random(nums, N); sort(nums, N); sort_check(nums, N); return 0; } /* * fills nums[0 .. size-1] with a random sequence of integers */ void fill_with_random(int nums[], int size) { int i; for (i = 0; i < size; ++i) { nums[i] = rand(); /* printf("%d\n", nums[i]); */ } } /* * prints "sort succeeded" if nums[0 .. size-1] is in order, * "sort failed" if not */ void sort_check(int nums[], int size) { int i; for (i = 0; i < size-1 ; ++i) { if (!(nums[i] <= nums[i+1])) { printf("sort failed\n"); return; } } printf("sort succeeded\n"); } /* * sorts nums[0 .. size-1] */ void sort(int nums[], int size) { }