Fast sorting Method C language implementation

Source: Internet
Author: User

The fast sorting method is an improvement to the bubbling sorting method. His basic idea is to divide the data into two separate parts, one by one, in which all of the data is smaller than the other, to sort the entire data.

First select a data as the Datum x usually selects the first data. Set two variables i,j start sorting i = 0 J = N-1 (here N is the number of data). Search from J, that is, search from backward forward, find the value less than X to Exchange. , then search from I, find a value greater than x Exchange both, cross-repeat the above two steps, until i = J;

As an example:

A[0] a[1] a[2] a[3] a[4] a[5]

49 38 65 97 76 13

To do the first sort:

Results after Exchange 13 38 65 97 76 49 at this time J = 4;

Second Order:

Results after Exchange 13 38 49 97 76 65 at this time i = 2;

Third Order:

Results after Exchange 13 38 49 97 76 65 at this time J = 2;

I = J Quick Sort ends. {13 38} 49 {97 76 65} achieves expected results

Fast sorting Method C language implementation

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.