Talk C Chestnut Bar (30th: C-language example-quick sort)

Source: Internet
Author: User


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)

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.