#include
int Partition(int r[],int i,int j) //快速排序的一次划分
{
int temp=r[i];
while(i
while (i
if(i
r[i++]=r[j];
}
while (i
}
}
r[i]=temp;
return i;
}
void QuickSort(int r[],int i,int j) //快速排序
{
if(i
int pivot=Partition(r,i,j);
QuickSort(r,i,pivot-1);
QuickSort(r,pivot+1,j);
}
}
main()
{
int i,q;
int a[1000];
printf("Enter the num of array:\n");
scanf("%d",&q);
printf("Enter the member of array:\n");
for(i=0;i scanf("%d",&a[i]);
QuickSort(a,0,q-1);
printf("QuickSort:\n");
for(i=0;i {
printf("%d ",a[i]);
}
printf("\n");
}
已测试 比如
Enter the num of array:
10
Enter the member of array:
6 3 8 2 5 9 5 2 5 10
输出
QuickSort:
2 2 3 5 5 5 6 8 9 10