JDK1.7 java.uti.Arrays start using dualpivotquicksort as the default sorting method
Detailed Links: http://www.tuicool.com/articles/BfY7Nz
Algorithm idea:
Two pivot P1 and P2are selected, requiring 3 pointer l,k,g.
The functions of 3 pointers are as follows:
The algorithm is for the following steps: (using dualpivotquicksortwhen the array size is less than 286 )
1, smaller than the array, using the insertion sort.
2, select Pivot P1 and P2. (Suppose you use array headers and tails).
3, P1 need less than P2, no exchange.
Now the array is divided into 4 parts, left to l the number of less than P1, l to K is greater than P1 less than P2 number, G to rigth greater than the number of P2, pending K to G in the middle of the number (gradually processed into the first 3 regions).
Key Algorithms Section
4, L from start initialization until not less than p1,k initialized to l-1,g from the end of the initialization until not much more than P2. K is a pointer to the main movement, to devour the middle area step-by-step.
When greater than P1 is less than p2,k++.
When less than P1, the number of exchanges L and K, l++,k++.
When greater than P2, if the number of G is less than P1, the number on the L on K, put the number of G on L, l++, and then put K before the number of G, g--,k++, complete a l,k,g exchange. Otherwise exchange K and G, and g--,k++.
5, recursion 4.
6, Exchange P1 to L-1. Swap P2 to g+1.
7, recursion.
Flow chart:
Java Collection (14)--double pivot quick sort (dualpivotquicksort)