优先级队列
作者:
黄河_2
,
2024-06-07 16:32:46
,
所有人可见
,
阅读 5
//宏文本替换,待更新
#define Inheap(n,i) (-1<i && i<n)
#define Parent(i) ((i-1)>>1)
#define LastInternal(n) Parent(n-1) //最后一个内部节点
#define Lchild(i) (1+((i)<<1))
#define Rchild(i) ((1+(i))<<1)
#define ParentVaild(i) (0<i)
#define LchildVaild(n,i) Inheap(n,Lchild(i))
#define RchildVaild(n,i) Inheap(n,Rchild(i))
#define Bigger(PQ,i,j) (lt(PQ[i],PQ[j])?j:i)
#define ProperParent(PQ,n,i) (RchildVaild(n,i)?Bigger(PQ,Bigger(PQ,i,Lchild(n,i)),Rchild(i)):\
(LchildVaild(n,i)?Bigger(PQ,i,Lchild(i)):i) ) //父子三者最大的 ,考虑存在不存在的事
#include "../Vector/Vector.h"
#include "../PQ/PQ.h"
typedef int Rank;
template <typename T> class PQ_ComplHeap :public PQ<T>,public Vector<T>{
protected:
Rank percolateDown(Rank n,Rank i);
Rank percolateUp (Rank i);
void heapify(Rank n);
}