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)