#include "stdio.h"
#define MAXSIZE 20
typedef int ElemType;
typedef struct
{
ElemType r[MAXSIZE+1];
int length;
}SortList;
//简单选择排序
void SelectSort(SortList *L)
{
int i,j;ElemType t;
for(i=1;i<L->length;i++)
for(j=i+1;j<=L->length;j++)
if(L->r[i]>L->r[j])
{t=L->r[i];L->r[i]=L->r[j];L->r[j]=t;}
}
//改进算法
void SelectSort(SortList *L)
{
int i,j;ElemType t;
for(i=1;i<L->length;i++)
{
for(k=i,j=i+1;j<=L->length;j++)
if(L->r[k]>L->r[j]) k=j;
if(k!=i)
{
t=L->r[k];L->r[k]=L->r[i];L->r[i]=t;
}
}
}
//堆排序
void AdjustTree(SortList *L,int n,int k)
{
int i,j;
i = k; j = 2*i;
L->r[0] = L->r[i];
while(j<=n)
{
if(j<n&&L->r[j+1]>L->r[j])
j = j+1;
if(L->r[0]>L-r[j])break;
L->r[i] = L->r[j];
i = j; j = 2*i;
}
L->r[i] = L->r[0];
}
void HeapSort(SortList *L)
{
int i;ElemType t;
for(i=L->length/2;i>=1;i--)
AdjustTree(L,L->length,i);
for(i=L->length;i>=2;i--)
{
t = L->t[i];
L->r[i] = L->r[1];
L->r[1] = t;
}
AdjustTree(L,i-1,1);
}