#include<stdio.h> #define n 10 //定义数字的长度 int Partition(int *r,int low,int high) //一趟快速排序 { r[0]=r[low]; while(low<high) { while(low<high&&r[high]>=r[0]) --high; r[low]=r[high]; while(low<high&&r[low]<=r[0]) ++low; r[high]=r[low]; } r[low]=r[0]; return low; } void Qsort(int *r,int low,int high) //递归方式进行几趟快速排序 { int p; if(low<high) { p=Partition(r,low,high); Qsort(r,low,p-1); Qsort(r,p+1,high); } } void Quicksort(int *r) //对顺序表r做快速排序 { Qsort(r,1,10); } void main() { int r[11]; printf("请输入十个数:/n"); for(int m=1;m<11;m++) scanf("%d",&r[m]); Quicksort(r); printf("排序后:/n"); for(m=1;m<11;m++) printf("%d ",r[m]); printf("/n"); }