Five, quick sort
Fast sorting is one of the most common sort algorithms, including C qsort,c++ and Java sort, with fast rows (c + + and Java sort optimized and mixed with other sorting algorithms).
Fast row worst case O (n^2), but the average efficiency o (n lg N), and this o (n lg N) Number of the implied constant factor is very small, fast row can be said to be the fastest sorting algorithm, not the wave of the title. It is also sorted in place.
A quick sort is based on a divide-and-conquer model:
Decomposition: Array A "p.. R "is divided into two (possibly empty) sub arrays a" p. Q-1 "and a" Q+1..R ", so that a" p. Each element in Q-1 is less than or equal to a (q) and is less than or equal to the element in a "Q+1..R". Subscript Q is also 迕 in the return partitioning process.
Workaround: Quick Sort by recursive invocation, sub array a "P". Q-1 "and a" q+1..r "sort.
Merging: Because two sub arrays are sorted in place, merging them does not require an action: the entire array a "P". R "is sorted.
The following procedure implements a quick sort:
Array partitioning: Partition (key, it's sub-array a "p. R "for in-place rearrangement)