Sorting is often used in a variety of situations.
Fast sequencing is a very common and efficient algorithm.
The idea is: choose a ruler First,
Use it to pass the whole queue through the sieve,
To ensure that the left element is not greater than it, and that the element on its right is not less than it.
In this way, the sorting problem is divided into two sub-intervals.
It is possible to sort the sub-intervals separately.
The following code is an implementation, please parse and fill in the missing code in the dash section.
#include <stdio.h>voidSwapintA[],intIintj) { intt =A[i]; A[i]=A[j]; A[J]=t;}intPartitionintA[],intPintR) { inti =p; intJ = R +1; intx =A[p]; while(1){ while(I<r && a[++i]<x); When while () is stopped, a[i]>x, or i>=r, is all a[i]<x while(a[--j]>x); When while () is stopped, the A[j]<xif(I>=J) Break; Abnormal case, then there must be a[j]<a[i], at this time a[i] is still greater than x,x position in the p,p on J left, also on I left.
Swap (A,I,J); Normal conditions I<j<r, a[i] and A[j] exchange, x position unchanged} ______________________; Therefore, fill in the Swap (A,P,J)
returnJ;}voidQuicksortintA[],intPintR) { if(p<R) { intQ =partition (A,P,R); Quicksort (A,p,q-1); Quicksort (A,q+1, R); }} intMain () {inti; intA[] = {5, -,6, -,2,8, +, -,6, A,1, -}; intN = A; Quicksort (A,0, N-1); for(i=0; i<n; i++) printf ("%d", A[i]); printf ("\ n"); return 0;}
Note: Fill in only what is missing, and do not write any existing code or descriptive text on any of the surfaces.
04 Quick Sort (code blank)