/**** * This version uses qs.c to do the work. * See quick.c for the details. * * One way to compile this is the following, * which first creates qs.o and then compiles * qs_main ("-lm" loads the math library, which * is needed if I'm #including-ing ). * * $ gcc -c qs.c * $ gcc -lm qs_main.c qs.o -o qs * ****/ #include #include #include #include "qs.h" #define MAX_ITEMS 10000 #define MAX_N 7 int numbers[MAX_ITEMS]; int n[] = {10, 30, 100, 300, 1000, 3000, 10000}; int main(){ int i, i_n, count; double nlogn; printf("# quicksort analysis \n"); printf("# %16s %16s %24s\n", "n", "count", "(n log(n)/count)" ); //seed random number generator srand(getpid()); for (i_n=0; i_n < MAX_N; i_n++){ //fill array with n[i_n] random integers for (i = 0; i < n[i_n]; i++){ numbers[i] = rand(); } //perform quick sort on array count = quickSort(numbers, n[i_n]); // and report how many steps it took nlogn = n[i_n]*log10((double)1.0*n[i_n]); printf(" %16i %16i %24.2f\n", n[i_n], count, nlogn/count); } }