Ladies and gentlemen, crossing, the last time we were talking about the choice of sorting examples, this time we say the example is: Quick sort. Gossip Hugh
The words return to a positive turn. Let's talk C chestnuts together!
the principle of quick sorting : Select a keyword to divide the container into two parts, any element in a part is a keyword, and the other part
Any element is smaller than the keyword. The two sections are then sorted separately.
Quick Sort Implementation steps :
- 1. Select a keyword, I directly use the container header element in the code as a keyword;
- 2. Traverse the container from the end of the container to the head until it encounters a smaller element than the key, and then swap it to the left of the key point;
- 3. Traverse the container from the head to the tail of the container until it encounters a larger element than the key, and then swap it to the right of the key point;
- 4. Repeat steps 2 and 3 until you meet in steps 2 and 3 in the traversal process;
- 5. At this point, the boundary of the container is found, the element on the left of the dividing point is larger than the key, and the element on the right is smaller than the key.
- 6. Repeat steps 1 through 5 for the element to the left of the cutoff point, and use recursion to implement this step in the program;
- 7. Repeat steps 1 through 5 for the element to the right of the cutoff point, using recursive return in the program to implement this step.
Crossing, the text does not write code, the detailed code put in my resources, you can click here to download the use. Quick Sort is
The best performance in all sorting algorithms, which is why it is called fast sorting.
Crossing, we're going to talk about the quick sort example here. 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 (30th: C-language example-quick sort)