#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"math.h"
#define MAXSIZE 20
#define LT(a,b) ((a)<(b))
typedef int KeyType;
typedef int InfoType;
typedef struct{
KeyType key;
InfoType otherinfo;
}RedType;
typedef struct{
RedType r[MAXSIZE+1];
int length;
}SqList;
int SelectMinKey(SqList L,int i)
{
int k;
int j;
k=i;
for(j=i;j<L.length+1;j++)
if(L.r[k].key>L.r[j].key)
k=j;
return k;
}
void SelectSort(SqList *L)
{
RedType t;
int i,j;
for(i=1;i<L->length;++i){
j=SelectMinKey(*L,i);
if(i!=j) {
t=L->r[i];
L->r[i]=L->r[j];
L->r[j]=t;
}
}
} //SelectSort
void main()
{int a[]={49,38,65,97,76,13,27,49};
int i,k;
SqList s;
printf("\nThe record to be sort:\n");
for(i=1;i<9;i++)
{s.r[i].key=a[i-1];
printf("%d ",a[i-1]);
}
s.length=i-1;
QuickSort(&s);
printf("\nThe records be sorted:\n");
for(i=1;i<9;i++)
printf("%d ",s.r[i].key);
printf("\n\n\tPress any key to exit.\n");
getch();
}
用VC调试