A quick sort is an improvement to the bubbling sort. Its basic idea is: by a trip to sort the data to be sorted into two separate parts, one part of all the data is smaller than the other part of all the data, and then the second method of the two parts of the data are quickly sorted, the entire sorting process can be recursive, so as to achieve the entire data into an ordered sequence.
Suppose the array to be sorted is a[1] ... A[n], the first arbitrary selection of data (usually the first data) as the key data, and then put all the more than its number in front of it, all the larger than its number is placed behind it, this process is called a fast sort of a trip. A quick sort of algorithm is:
1) Set two variables I, J, when the sorting starts i=0,j=n-1;
2) with the first array element as the key data, assign the value to X, i.e. x=a[0];
3) Forward search from J, that is, after the start of the search, find the first value less than X, the two exchange;
4) from I start backward search, that is, from the front to start backward search, find the first value greater than X, the two exchange;
5) Repeat the 3rd and 4 steps until i=j;
---------------------Reference Code-------------------------
void Quiksort (int a[],int low,int high) { int i = low; int j = high; int temp = A[i]; if (Low < high) {when (i < J) {while ( (a[j] >= temp) && (i < J)) { j--;
} A[i] = a[j]; while ((A[i] <= temp) && (i < J)) { i++; } a[j]= a[i]; } A[i] = temp; Quiksort (a,low,i-1); Quiksort (A,j+1,high); } else { return; }} int main () { int arry[5] = {23,1,21,4,19}; Quiksort (arry,0,4); for (i=0;i<5;i++) { printf ("%d", Arr[i]); } printf ("\ n");}
C language-sort-quick sort