1 #include <stdio.h> 2 int a[101], n; 3 4 void quickSort(int left, int right){ 5 int i, j, t, temp; 6 if (left > right) 7 return; 8 9 temp = a[left]; 10 i = left; 11 j = right; 12 while (i != j){ 13 while (a[j] >= temp && i < j) 14 j--; 15 while (a[i] <= temp && i < j) 16 i++; 17 if (i < j){ 18 t = a[i]; 19 a[i] = a[j]; 20 a[j] = t; 21 } 22 } 23 a[left] = a[i]; 24 a[i] = temp; 25 26 quickSort(left, i - 1); 27 quickSort(i + 1, right); 28 } 29 30 int main(void){ 31 int i; 32 printf("请输入您要输入的数据个数:"); 33 scanf("%d", &n); 34 for (i = 1; i <= n; i++){ 35 scanf("%d", &a[i]); 36 } 37 quickSort(1, n); 38 39 for (i = 1; i <= n; i++) 40 printf("%d ", a[i]); 41 42 getchar(); 43 return 0; 44 }