#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAXSIZE 100
#define MinPQSize 1
typedef int ElementType;
struct HeadStruct{
int Capacity;
int Size;
ElementType *Elements;
};
typedef struct HeadStruct *PriorityQueue;
//是否为空
int IsEmpty(PriorityQueue H)
{
return H->Size == 0 ? 1 : 0;
}
//是否为满
int IsFull(PriorityQueue H)
{
return H->Size == H->Capacity ? 1 : 0;
}
//初始化
PriorityQueue Initialize(int MaxElements)
{
PriorityQueue H;
if(MaxElements < MinPQSize)
{
printf("Priority queue is too small");
exit(0);
}
H = (PriorityQueue)malloc(sizeof(struct HeadStruct));
if(H == NULL)
{
printf("out of space");
exit(0);
}
H->Elements = (ElementType*)malloc((MaxElements + 1) * sizeof(ElementType));
if(H->Elements == NULL)
{
printf("out of space");
exit(0);
}
H->Capacity = MaxElements;
H-
优先队列的简单实现
最新推荐文章于 2021-03-17 15:14:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)