📄 priority_queue.h
字号:
#ifndef PRIORITY_QUEUE_H
#define PRIORITY_QUEUE_H
#define MAX_NUM 200 //优先队列里最多能存的元素个数
typedef struct Edge
{
int v; //起点
int w; //终点
int weight; //边的权值
}Edge;
/**---每次只能出队列中的最小值的优先队列----*/
typedef struct priority_queue
{
struct Edge* h[MAX_NUM+1]; //用来存优先队列里的元素的,元素从1开始存,
int n ; // 元素存放时应该放的位置,
} priority_queue;
Status init_priority_queue(priority_queue* pq);
//初始优先队列
//Edge* IninEdge(int a,int b,int c);
//初始化优先队列里面的元素
Status Destory_priority_queue(priority_queue* pq);
//销毁优先队列
Status max_heapify(priority_queue* pq,int i);
//每次插入后进行的堆调整,因为每次都插入到最后,前面的元素都符合堆的要求,
//调整成功返回0,不成功返回-1
int min_heapAdjust(priority_queue* pq,int n);
//已知pq[1....n]中记录的关健字除pq[1]外均满足堆的定义,本函数调整L[1]的关健字
//使L[1...m]成为一个小顶堆,调整成功返回0,不成功返回-1
Status insert_priority_queue(priority_queue* pq,Edge* t);
//向队列pq中插入一元素 t, 操作成功返回0,操作失败返回-1
Edge* extract_min(priority_queue* pq);
//队列pq中返回最小值,并删除了最小值
Edge* Get_Min(priority_queue* pq);
//仅仅从队列pq中获得了最小值
int isEmpty(priority_queue* pq);
//队列为空返回true, 否则返回false
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -