//这两个是下标法和指针法,数组名法不知道是个什么概念。
#include<stdio.h>
void swap(int*a,int*b)
{
int tmp;
tmp=*a;*a=*b;*b=tmp;
}
void FastSorting1(int n[],int start,int end)
{
int head=start,tail=end;
int divider=n[start];
if(start>=end) return;//递归基
while(head<tail)
{
while(n[tail]>divider) tail--;
while(n[head]<divider) head++;
swap(&n[head],&n[tail]);
}
FastSorting1(n,start,head);
FastSorting1(n,head+1,end);
}
void FastSorting2(int*n,int length)
{
int divider=*n;
int*head=n;int*tail=n+length-1;
if(length<=1) return;
while(head<tail)
{
while(*tail>divider) tail--;
while(*head<divider) head++;
swap(head,tail);
}
FastSorting2(n,head-n);
FastSorting2(head,length-(head-n)-1);
}
int main()
{
int arr[7];int i;
printf("排序前:\n");
for(i=0;i<7;i++)
printf("%d,",arr[i]=(int)rand()%20);
FastSorting1(arr,0,6);
printf("\n排序后:\n");
for(i=0;i<7;i++)
printf("%d,",arr[i]);
/*重新试过*/
printf("\n排序前:\n");
for(i=0;i<7;i++)
printf("%d,",arr[i]=(int)rand()%20);
FastSorting2(arr,7);
printf("\n排序后:\n");
for(i=0;i<7;i++)
printf("%d,",arr[i]);
return 0;
}