1、二叉堆的操作
(1)取出元素
(2)插入元素
(3)删除元素
//手写大根堆维护 #include<bits/stdc++.h> using namespace std; int heap[1000]; int up(int x) { if(heap[x]<=heap[x/2]) return 0; else { swap(heap[x],heap[x/2]); up(x/2); } } int down(int x) { if(heap[x]>=heap[x*2]&&heap[x]>=heap[x*2+1]) return 0; else if(heap[x*2]>heap[x*2+1]) { swap(heap[x],heap[x*2]); down(x*2); } else { swap(heap[x],heap[x*2+1]); down(x*2+1); } } int m,od,x,n; int main() { scanf("%d",&m); while(m--) { scanf("%d",&od); if(od==1) { printf("%d",heap[0]); } if(od==2) { scanf("%d",&x); n++; heap[n]=x; up(n); } if(od==3) { heap[0]=heap[n]; n--; down(1); } } return 0; }