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