#define MinData (-32767)
typedef int ElementType;
struct HeapStruct;
typedef struct HeapStruct *PriorityQueue;
struct HeapStruct
{
int Capacity;
int Size;
ElementType *Elements;
};
PriorityQueue initialize(int MaxElemenes)
{
PriorityQueue H;
H=(PriorityQueue)malloc(sizeof(struct HeapStruct));
H->Elements=(ElementType *)malloc((MaxElemenes+1)*sizeof(ElementType));
H->Capacity=MaxElemenes;
H->Size=0;
H->Elements[0]=MinData;
return H;
}
void PercDown(PriorityQueue H, int i)
{
ElementType Tmp;
int child;
for (Tmp=H->Elements[i]; 2*i <= H->Size; i= child)
{
child= i*2;
if (child!=H->Size && H->Elements[child+1] < H
用线性时间算法建立二叉堆。
最新推荐文章于 2021-09-24 15:59:49 发布