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.