C language selection and sorting

Source: Internet
Author: User

C language selection and sorting

Select-based sorting is a relatively understandable sorting algorithm. Assume that you want to sort the sequences with n numbers in ascending order. The algorithm steps are as follows:

1. Find the subscript of the minimum number from the number of n stored in the array (for the algorithm, see "Calculate the most value" below), and then swap the minimum number with the number of 1st;

2. Except for 1st, we can find the subscript of the smallest number (the secondary decimal number in n) from the other n-1 numbers, and swap the number with 2nd;

3. Repeat Step 1 n-1 to complete the request.

Now let's look at the Code:

 

# Include

 
  
# Include

  
   
# Define n 10 int main () {int a [n], I, j, k, t; printf ("randomly generate 10 numbers less than 100: \ n "); for (I = 0; I

   
    
Running result:

    

 

Generate 10 numbers less than 100 at random and output them after sorting.

Related Article

Contact Us

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.