/***************** * sorting_template.c * * template for sorting in C * * For C syntax and libraries, see * https://cs.marlboro.college/courses/spring2016/systems/c_refcard.pdf * * TODO : * * - first, make a copy of this file, as sort_XXX.c * where XXX is your name or an algorithm or whatever; * do your work on that copy. * * - implement and test the "insertion" sorting algorithm. * (i) watch it work for a small n value, printing everything, then * (ii) try it on a larger (10 numbers or so) test case, then * (iii) put in a loop invariant to show explicitly that it works. * * - add loop over multiple values for n, with output performance * (and remove printing the whole thing, of course) * * - invoke from command line with piped output, sending output * to a file for safe keeping , i.e. * * $ gcc sort_XXX.c -o sort_XXX * $ ./sort_XXX > sort_XXX_output.txt * * - profit. ;) * * Jim Mahoney | cs.bennington.college | MIT License | March 2022 *****************/ #include #include #include #include double get_secs(){ // return time since program launch clock_t ticks = clock(); double seconds = (double)ticks / (double)CLOCKS_PER_SEC; //printf(" ticks since epoch = %lu ; ", ticks); // debug //printf(" ticks per second = %d \n", CLOCKS_PER_SEC); // . //printf(" seconds = %.6f \n", seconds); // . return seconds; } int* get_randoms(int n){ // return array of n random numbers, randoms[0] to randoms[n-1]. int i; int* randoms = malloc(n * sizeof(int)); for (i=0; i