The fast sorting algorithm is a very efficient internal sorting algorithm with an average time complexity of O (Nlogn), and its performance is best in the same time complexity, but
In the worst case, it will degenerate into a bubbling sort, where the time complexity is O (n^2). In terms of average performance, fast sequencing is a very efficient algorithm, and now
This paper introduces a simple implementation algorithm for fast sorting.
The code is as follows:
#include <stdio.h> #define N 10int main () {void sort (int *a, int left, int. right), int a[n];int i;for (i = 0; i < N; i++) scanf ("%d", &a[i]); sort (A, 0, N-1); Defect, when called in the main function, to check if left is less than rightfor (i = 0; i < N; i++) printf ("%d", A[i]); return 0;} void sort (int *a, int left, int right) {if (left < right) //When only one data is returned, that is, leave = = Right{int Key = A[left];int Low = Le Ft;int high = right;while (Low < High) {when (Low < high && A[high] >= key) High--;a[low] = A[high];while (l ow < high && A[low] <= key) Low++;a[high] = A[low];} A[low] = Key;sort (A, left, low-1); Sort the left half (a, low+1, right); Sort the right half of the part}}
Fast sorting algorithm