最大堆最小堆(自定义类型)
2013-03-24 18:47
260 查看
#include<queue> #include "stdio.h" using namespace std; struct node { int x , y; bool operator <(node a)const //最大堆重载 { return y<a.y; } bool operator >(node a)const//最小堆重载 { return y>a.y; } }; int main(int argc, char* argv[]) { priority_queue<node> max; priority_queue<node,vector<node>,greater<node> > min; int i ; for( i = 0 ; i<10 ; i++) { node n ; n.x = i ; n.y = i; max.push(n); min.push(n); } for( i = 0 ; i<10 ; i++) { printf("%d ", max.top().y); max.pop(); } for( i = 0 ; i<10 ; i++) { printf("%d ", min.top().y); min.pop(); } printf("Hello World!\n"); return 0; }
相关文章推荐
- typedef(自定义数据类型)与#define(宏定义)用法比较(前者定义指针比define好用)
- MOSS创建自定义字段类型
- Android--自定义属性,attr format取值类型
- SpringMVC自定义日期类型的数据绑定
- JAVA问题总结之4--各大数据类型能存的最大最小值
- Hadoop自定义数据类型
- 百度地图的使用定位,逆地理编码,自定义不同类型的大头针
- 统一绑定下拉框控件;设置同一类型的控件的属性;自定义错误处理类
- 一个关于自定义类型作为HashMap的key的问题
- Hadoop 高级程序设计(一)---复合键 自定义输入类型
- Javascript 自定义类型
- C# 使用DateTime.TryParseExact将自定义日期类型转换成日期
- Hadoop自定义类型处理手机上网日志
- poj1442(最大最小堆)
- [翻译]怎么使用LINQ方法来比较自定义类型对象
- SpringMVC第四篇【参数绑定详讲、默认支持参数类型、自定义参数绑定、RequestParam注解】
- PAT-求自定类型元素的最大值(基础函数题)
- 【C++学习笔记】处理类型和自定义数据结构
- 数据大小超出此类型的最大值
- Mybatis自定义typeHandler实现类型转化