/* * Program to test sort function: * Generate a random sequence of ARRAY_SIZE integers, sort them, and check * that the sort succeeded. (ARRAY_SIZE is hardcoded for now, and the sort * function doesn't do anything, so will almost surely fail!) */ #include #include #define ARRAY_SIZE 100 /* function declarations */ void fill_with_random(int data[], int size); void sort(int data[], int size); void check_sorted(int data[], int size); /* main program */ int main(void) { int data[ARRAY_SIZE]; fill_with_random(data, ARRAY_SIZE); sort(data, ARRAY_SIZE); check_sorted(data, ARRAY_SIZE); return 0; } /* fill array with randomly generated data */ void fill_with_random(int data[], int size) { for (int i = 0; i < size; ++i) { data[i] = rand(); /* printf("%d\n", data[i]); */ } } /* check whether array is sorted and print sorted / not sorted */ void check_sorted(int data[], int size) { for (int i = 0; i < size-1; ++i) { if (data[i] > data[i+1]) { printf("not sorted\n"); return; } } printf("sorted\n"); } /* sort array */ void sort(int data[], int size) { }