标签:cc++
快速排序是基于分治思想的排序,以递增排序为例:示例代码如下:
#include<stdio.h>
#define Elemtype int
int partion(Elemtype A[],int low,int high)
{
Elemtype pivot=A[low];
while(low<high)
{
while(low<high&&A[high]>=pivot)high--;
A[low]=A[high];
while(low<high&&A[low]<=pivot)low++;
A[high]=A[low];
}
A[low]=pivot;
return low;
}
void quicksort(int A[],int low,int high)
{
if(low<high)
{
int pivotpos=partion(A,low,high);
quicksort(A,low,pivotpos-1);
quicksort(A,pivotpos+1,high);
}
}
int main()
{
int A[12]={12,3,4,5,6,77,4,22,22,3,5,7};
quicksort(A,0,11);
for(int i=0;i<12;i++)
{
printf("%d ",A[i]);
}
}标签:cc++
原文地址:http://blog.csdn.net/u010839382/article/details/39958777