QuickSort

来源:互联网 发布:·手机淘宝 编辑:程序博客网 时间:2024/06/05 00:18
#include<stdio.h>
#define MAXE 20
typedef int KeyType;
typedef char InfoType;
typedef struct

     KeyType key;
InfoType data;
}RecType;
void QuickSort(RecType R[],int s,int t)
{
int low=s,high=t;
     R[0]=R[low];
RecType pivotkey=R[s];
while(low!=high){
     while(low<high&&R[high].key>pivotkey.key)
 --high;
 if(low<high)
 R[low++]=R[high];
 while(low<high&&R[low].key<pivotkey.key)
 ++low;
 if(low<high)
 R[high--]=R[low];
}
R[low]=pivotkey;
printf("划分区间为R[%d..%d],结果为:",low,high);
for(int k=0;k<10;k++)
if(k==low)
printf("[%d]",R[k].key);
else
printf("%3d",R[k].key);
printf("\n");
QuickSort(R,s,low-1);
QuickSort(R,low+1,t);
}
0 0