/已知关键字序列(K1,K2,K3,…,Kn-1)是一个大根堆/
/试写一算法将(K1,K2,K3,…,Kn-1,Kn)调整为大根堆/
/利用该算法写一个建大根堆的算法/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAXSIZE 20
typedef int KeyType;
typedef int InfoType;
typedef struct
{
KeyType key;
InfoType otherinfo;
}RedType;
typedef struct
{
RedType r[MAXSIZE+1];
int length;
}SqList;
void HeapAdjust(SqList *L,int n);
void Swap(SqList *L,int low,int high);
void HeapSort(SqList *L);
int main()
{
SqList *L;
L=(SqList *)malloc(sizeof(SqList));
int i;
printf("需调整的关键字序列项数(其中除最后一项外,其余均符合大根堆):");
scanf("%d",&L->length);
for(i=0;i<L->length;i++)
{
printf("please input the number:");
scanf("%d",&L->r[i+1].key);
}
HeapSort(L);
printf("the result is:");
for(i=0