This article is not about a specific sorting algorithm, but about some preparation work.
1. Generate 10000 random numbers as the data source for subsequent testing of the sorting algorithm.
/* Generate 10000 repeated random numbers, save them to the file, and calculate the generation time */# include <stdio. h> # include <stdlib. h ># include <ctime> typedef long clock_t; void main () {clock_t start_time = clock (); // start time srand (unsigned (time (0 ))); // generate the time seed. The header files of the srand () and rand () functions are <stdlib. h>. // Rand () generates pseudo-random numbers. srand () seeds are different, and the random series generated by rand () are different. The probability of the same random number is smaller. // The random numbers generated by two consecutive rand () are the same. // Rand () defaults to 0 ~ Rand_max (defined in stdlib. H, the default size is 32767. Const int max = 10000; const int min = 1; // locate the standard output stream to the file if (freopen ("data.txt", "W", stdout )) = NULL) Exit (-1); For (INT I = 0; I <10000; I ++) {unsigned int DATA = rand (); printf ("% d", data);} // locate the standard output stream to the console if (freopen ("con", "W", stdout) = NULL) exit (-1); clock_t stop_time = clock (); printf ("elapsed time: % DMS \ n", (stop_time-start_time ));}
2. Print array elements
# Include "print. H "// output the sorting result of each step void print (int A [], int N) {for (INT I = 0; I <n; I ++) {printf ("% d", a [I]);} printf ("\ n ");}