Fast sorting is a very common sort algorithm.
/* * Quick Sort (pseudo algorithm) 2016-04-20 23:34:16 * 1. First find the final position of the first element * 2. The element before the final position of the first element, For quick sorting. * 3. Quickly sorts the elements after the final position of the first element. **/extern void quicksort (Int a[],int low,int high);//The second parameter represents the subscript of the first element, The third parameter represents the subscript Extern intfindpos (Int a[], int low, int high) of the last element; Extern int findpos (int a[], int start, int end) {int val;val = a[start]; while ( start < end ) {while ( (start < end ) && ( a[end] > val ) ) {--end;} a[start] = a[end];while ( ( start < end ) && ( a[start] < val ) ) {++start;} A[end] = a[start];} A[start] = val;return start;} Extern void quicksort (int a[], int start, int end) {int pos;// A place that often goes wrong 1. Here should be judged by ifInstead of a loop. if (start < end) {pos = findpos (a, start, end); QuickSort (a, start, pos - 1); QuickSort (A, pos + 1, end);}}
This article is from the "Do Your best" blog, so be sure to keep this source http://qiaopeng688.blog.51cto.com/3572484/1766040
A quick sort of the classic sorting algorithm (C language version)