堆的实现andprioity-queue函数
来源:互联网 发布:培罗成西服淘宝店 编辑:程序博客网 时间:2024/06/09 18:32
int heap[maxn],sz=0;
void push(int x)
{
int I=sz++;
while(I>0)
{
int p=(I-1)/2;
if(head[p]<=x)
break;
head[I]=head[p];
I=p;
}
head[I]=x;
}
int pop()
{
int ret=heap[0];
int x=head[--sz];
int I=0;
while(I*2+1<sz)
{
int a=I*2+1,b=I*2+2;
if(b<sz&&head[b]<head[a]) a=b;
if(head[a]>=x) break;
head[I]=head[a];
I=a;
}
head[I]=x;
return ret;
}
priorty_queue函数
#include<queue>
#include<cstdio>
using namespace std;
int main()
{
priorty_queue<int>pque;
pque.push(3);
pque.push(5);
pque.push(1);
while(!pque.empty())
{
printf("%d\n",pque.top());
pque.pop();
}
return 0;
}
0 0
- 堆的实现andprioity-queue函数
- min heap priority queue 最小堆实现的优先队列
- 【JDK】Priority Queue 堆实现源码详解
- 堆的简单实现(仿函数)
- 【Scala类型系统】函数式Queue的简易实现
- queue的C++实现
- queue的实现 数据结构
- c++ Queue的实现
- 队列的实现 queue
- Queue的顺序实现
- 链式Queue的实现
- STL queue 的实现
- Queue的实现
- queue队列的实现
- Queue(3)Queue的链式实现
- tzc 2894 Windows Message Queue【堆排实现优先级FIFO
- Hdoj 1509 -Windows Message Queue 优先队列最小堆实现
- Implement queue with two stack 用两个堆实现队列
- 第一天开启CSDN博客之旅
- poj3020 Antenna Placement
- LIS和LCS
- 文章标题
- 2016多校第五场 1001 HDU 5781 DP
- 堆的实现andprioity-queue函数
- 弹性盒子flex布局实现骰子六个面并让骰子3D空间旋转
- 剑指offer 约瑟夫环问题
- BZOJ 2440 完全平方数(莫比乌斯反演+容斥原理+二分)
- iOS开发之获取APP在AppStore中的版本号
- asp.net从零开始---002--前端页面布局
- jQuery源码研究分析学习笔记-jQuery原型属性和方法(九)
- 你的产品没有一炮而红,后面该怎么办?
- 安卓实用方法,类,接口