constexpr int N = 10001;
struct Heap{
int datA[N]; // start from 1
int siz;
// int (*topper)(int, int);
#define topper(a, b) ((a)<(b))
void up(int id){
while(id!=1 && topper(datA[id], datA[id/2])){
std::swap(datA[id], datA[id/2]);
id/=2;
}
}
void down(int id){
while(id*2<=siz){
int t = id*2;
if(t+1<=siz && topper(datA[t+1], datA[t])) t++;
if(topper(datA[id], datA[t])) return;
std::swap(datA[id], datA[t]);
id=t;
}
}
void ins(int x){
siz++;
datA[siz] = x;
up(siz);
}
int gettop(){ return datA[1]; }
void deltop(){
std::swap(datA[1], datA[siz]);
--siz;
down(1);
}
void mk(){ for(int i=siz; i; --i) down(i); }
} hp;
标签:struct,int,二叉,start,topper,模板
From: https://www.cnblogs.com/x383494/p/17068871.html