#include <stdio.h>
/*
功能:快速排序
start表示起始位置指针,len表示要排序的长度
无返回值
*/
void qiuck_sort(int *start,int len)
{
int k;//用作记录枢轴记录关键字
int *p1,*p2,*pkey;//p1,p2分别表示高位和低位的指针,pkey枢轴记录关键字指针
if(len<=1)//1位不必排序
{
return;
}
pkey=start;//把第一为
k=*start;//记录枢轴记录关键字
p1=start;
p2=start+len-1;
while(p1<p2)
{
while(*p2>=k&&p1<p2)p2--;
*pkey=*p2;
pkey=p2;
while(*p1<=k&&p1<p2)p1++;
*pkey=*p1;
pkey=p1;
}
*p1=k;//填入枢轴记录
//分治为两部分递归
qiuck_sort(start,p1-start);
qiuck_sort(p1+1,start+len-p1-1);
}
/*
功能:快速排序
start表示起始位置指针,len表示要排序的长度
无返回值
*/
void qiuck_sort(int *start,int len)
{
int k;//用作记录枢轴记录关键字
int *p1,*p2,*pkey;//p1,p2分别表示高位和低位的指针,pkey枢轴记录关键字指针
if(len<=1)//1位不必排序
{
return;
}
pkey=start;//把第一为
k=*start;//记录枢轴记录关键字
p1=start;
p2=start+len-1;
while(p1<p2)
{
while(*p2>=k&&p1<p2)p2--;
*pkey=*p2;
pkey=p2;
while(*p1<=k&&p1<p2)p1++;
*pkey=*p1;
pkey=p1;
}
*p1=k;//填入枢轴记录
//分治为两部分递归
qiuck_sort(start,p1-start);
qiuck_sort(p1+1,start+len-p1-1);
}