递归实现随机数快排
#include <stdio.h> #include <stdlib.h> //quick sort void QuickSort(int r[], int first, int end) { if(first >= end) return; int mid = (first + end) / 2, i = first, j = end, x,temp; x = r[mid]; while(1) { while(r[i] < x) i++; while(r[j] > x) j–; if(i >= j) break; temp = r[i]; r[i] = r[j]; r[j] = temp; } QuickSort(r,first, j - 1); QuickSort(r,j + 1, end); return ; } void ShowArray(int r[], int first, int end) { int i; for (i = first; i <= end; i++) printf("%d “, r[i]); printf(”\n"); } int main() { int n, s, t; int r[20]; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &r[i]); s = 1, t =