Talk C Chestnut Bar (29th: C-language Instance-select sort)

Source: Internet
Author: User


Ladies and gentlemen, crossing, the last time we were talking about the example of hill sort, this time we say the example is: select Sort. Gossip Hugh

The words return to a positive turn. Let's talk C chestnuts together!


the choice of sorting is based on selecting a maximum or minimum element from the container, placing the element in a new container, and waiting for the container to be

Once the elements have been selected, the elements stored in the new container are ordered.


In implementing the selection sort, I took full advantage of the container's space by swapping the position of the element, without creating a new container, so that the section

Save the program's storage space. the implementation steps for selecting a sort are as follows:

1. First implement a function that can find the largest or smallest element in the device, and return the position of the element in the container after finding it;

2. First, the container head element as the largest or smallest element;

3. Start with the second element of the container and loop through the container;

4. Use the function in step 1 in the traversal process to find the maximum element or the location of the smallest element;

5. Compare the size of the two elements in step 2 and step 4, and then go back to step 2 if the collation is met;

6. Compare the size of the two elements in step 2 and step 4, and swap the values of the two elements if they do not conform to the collation;

7. Repeat step 2 through step 6 until the end of the container.


Crossing, the text does not write code, the detailed code put in my resources, you can click here to download the use.


Gentlemen, crossing, let's talk about the selection of sorts. I want to know what the following example, and listen to tell.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk C Chestnut Bar (29th: C-language Instance-select sort)

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.