Java implementation fast sorting algorithm _java

Source: Internet
Author: User

1, algorithm concept.

The quick sort (Quicksort) is an improvement on bubble sorting. by C. A. R. Hoare was introduced in 1962.
2, algorithmic thinking.

By sorting the data that will be sorted into two separate parts, a part of all the data is smaller than the other part of all the data, and then the two parts of the data for the rapid sorting, the entire sequencing process can be recursive, so as to achieve the entire data into an ordered sequence.

3, the realization of ideas.

① with the first keyword K 1 as the control word, divide [k 1, K 2,..., K N] into two subgroups so that all the keywords in the left area are less than or equal to K 1, all the keywords in the right area are greater than or equal to K 1, and the last control is the appropriate position in the middle of the two sub area. The data in the child area is still in an unordered state.
② the left area as a whole, with the ① steps for processing, the right side of the same treatment. (i.e. recursive)
③ repeats the ①, ② steps until the left area is processed.

public static void Quicksortbymid (int[] A, int low, int high) {
    if (low >= high) return
      ;
    Split
    int pivot = a[low];//reference value
    int i = low, j = high;
    while (I < j) {while
      (i < J && A[j] >= pivot)
        --j;
      A[I]=A[J];
      while (I < J && A[i] <= pivot)
        ++i;
      A[j]=a[i];
    }
    A[i]=pivot;
    Quicksortbymid (A, low, i-1);
    Quicksortbymid (A, i+1, high);
  

Quick Sort algorithm schematic diagram:

The above mentioned is the entire content of this article, I hope to learn Java fast sorting algorithm help.

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.