Two implementations of Java quick sort

Source: Internet
Author: User

Fast sorting, as long as the people who have learned the programming must have heard of this noun, but sometimes when the writing is really blindfolded, the online search and review of the "Introduction to Algorithm", temporarily find two ways to achieve the fast, recorded as follows:

1. By digging the pit, divide and conquer the way, need to alternately walk around

Thoughts are as follows:

Code implementation:

1      Public Static voidQuickSort1 (int[] A,intSinte) {2         if(S >=e)3             return;4         intm =A[s];5         inti = s, j =e;6          while(I <j) {7              while(A[j] > m && i <j)8j--;9             if(I <j)Tena[i++] =A[j]; One              while(A[i] < m && I <j) Ai++; -             if(I <j) -a[j--] =A[i]; the         } -A[i] =m; -QuickSort1 (A, S, i-1); -QuickSort1 (A, i + 1, e); +}
2. Divide the array into three parts: less than the median, greater than the median, and not processed, is an implementation provided in the introduction of the algorithm

Thoughts are as follows:

The code is as follows:

1      Public Static voidQuickSort2 (int[] A,intSinte) {2         if(S >=e)3             return;4         inti = s-1, j =s;5         intm =A[e];6          while(I <= J && I <= e && J <=e) {7             if(A[j] <=m) {8                 intTMP = a[++i];9A[i] =A[j];TenA[j++] =tmp; One             } A             Else -++J; -         } theQuickSort2 (A, S, i-1); -QuickSort2 (A, i + 1, e); -}

Two Java implementations of fast sequencing, which are later found to be complemented by other implementation ideas.

Two implementations of Java 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.