先看段代码:

struct node
{
friend bool operator< (node n1, node n2){ // 优先取最小的,它与下面的 // 是等价的
return n1.e > n2.e;
}
   //bool operator< (const node &r)const{ // <是重载运算符,不是普通的小于
    //    return s > r.s;
    //}
int s, e;
node(int a, int b){
s = a;
e = b;
}
};
//bool operator< (const node& a, const node& b){ // 其也是等价的
//    return a.s > b.s;
//} int main() {
priority_queue<node>que; // 此优先队列实现的是取最小的 que.push(node(1, 10));
que.push(node(5, 50));
que.push(node(2, 20));
while(!que.empty()){
printf("%d\n", que.top().s);
que.pop();
}
return 0;
}
 

在结构体中

struct node
{
int s, e;
node(int _v , int _c ):s(_v),e(_c){} // 这样写是可以进行附初值
// 同理与下面的 // 是等价的
//node(int a, int b){
//s = a;
//e = b;
//}
}; int main() {
queue<node>que; que.push(node(1, 10));
que.push(node(5, 50));
que.push(node(2, 20));
//while(!que.empty()){
//printf("%d\n", que.top().s);
//que.pop();
//}
while(!que.empty()){
printf("%d %d\n", que.front().s, que.front().e);
que.pop();
}
return 0;
}

最新文章

  1. 【2016-11-7】【坚持学习】【Day22】【Oracle 递归查询】
  2. MVC Core
  3. 模板类重载&lt;&lt;运算符
  4. windows下用一台机器配置分布式redis(主从服务器)
  5. ASP.NET 中OAUTH 2.0 及OPENID CONNECT的介绍
  6. ExtractNewFolderPath
  7. Websocket 与代理服务器如何交互? How HTML5 Web Sockets Interact With Proxy Servers
  8. weiphp 微信公众号用程序来设置指定内容消息回复业务逻辑操作
  9. shell 编程之 if...else case...esac
  10. Spring实现无需注解实现自动注入
  11. hihocoder Challenge 29 D. 不上升序列
  12. Android使用bindService作为中间人对象开启服务
  13. Kafka producer介绍
  14. Unity3D之游戏架构脚本该如何来写
  15. Problem of Uninstall Cloudera: Cannot Add Hdfs and Reported Cannot Find CDH&#39;s bigtop-detect-javahome
  16. Java代码度量分析工具:Designite简介
  17. 使用Git Wiki 管理文档时,文档编写的基本用法
  18. (LeetCode 72)Edit Distance
  19. Android开发牛刀小试之“AA算钱软件”开发(一)
  20. JS高级程序设计第三版——变量、作用域和内存问题

热门文章

  1. html(三)注册页面与重定向
  2. Python--day60--jinjia2模块
  3. H3C DNS域名解析原理
  4. linux 使用 gdb
  5. PHP判断类型
  6. tensorflow学习笔记——ResNet
  7. github权限管理
  8. Visio常规图表
  9. 基于TDengine-ver-1.6.4.4在windows 10下cmake+msys2编译(windows cgo 使用)
  10. java agent技术原理及简单实现