# Sorting Algorithm 00: Preparations

Source: Internet
Author: User

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 ");}`

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.