#include<stdio.h>
#include<stdlib.h>
#define MAX 10
typedef int keytype;
typedef struct
{
keytype key;
}Recnode;
Recnode r[MAX];
int n;
int partition(Recnode r[],int low,int high)
{
if(low>high) return 0;
if(low==high) return low;
r[0]=r[low];
while(low<high)
{
while(low<high&&r[high].key>=r[0].key)
if(low<high)
{r[low]=r[high];low++;}
while(low<high&&r[low].key<r[0].key)
if(low<high)
{r[high]=r[low];high--;}
}
r[low]=r[0];
return low;
}
void quicksort(Recnode r[],int m,int n)
{
int i;
i=partition(r,m,n);
quicksort(r,m,i-1);
quicksort(r,i+1,n);
}
int main()
{
Recnode r[MAX];
keytype a[]={75,87,68,92,88,61,77,96,80,72};
int n=10,i;
for(i=0;i<n;i++)
r[i].key=a[i];
printf("排序前:");
for(i=0;i<n;i++)
printf("%3d",r[i].key);
printf("\n");
quicksort(r,0,n-1);
printf("排序后:");
for(i=0;i<n;i++)
printf("%3d",r[i].key);
printf("\n");
system("pause");
}

#include<stdlib.h>
#define MAX 10
typedef int keytype;
typedef struct
{
keytype key;
}Recnode;
Recnode r[MAX];
int n;
int partition(Recnode r[],int low,int high)
{
if(low>high) return 0;
if(low==high) return low;
r[0]=r[low];
while(low<high)
{
while(low<high&&r[high].key>=r[0].key)
if(low<high)
{r[low]=r[high];low++;}
while(low<high&&r[low].key<r[0].key)
if(low<high)
{r[high]=r[low];high--;}
}
r[low]=r[0];
return low;
}
void quicksort(Recnode r[],int m,int n)
{
int i;
i=partition(r,m,n);
quicksort(r,m,i-1);
quicksort(r,i+1,n);
}
int main()
{
Recnode r[MAX];
keytype a[]={75,87,68,92,88,61,77,96,80,72};
int n=10,i;
for(i=0;i<n;i++)
r[i].key=a[i];
printf("排序前:");
for(i=0;i<n;i++)
printf("%3d",r[i].key);
printf("\n");
quicksort(r,0,n-1);
printf("排序后:");
for(i=0;i<n;i++)
printf("%3d",r[i].key);
printf("\n");
system("pause");
}
