C++ 优先队列priority_queue用法
2024-10-09 08:15:37
头文件:#include<queue>
操作:
- top 访问队头
- empty 队列是否为空
- size 返回队列元素个数
- push 插入元素到队尾
- pop 弹出队头
- swap 交换内容
定义:
/*
Type 数据类型
Container 容器类型(必须是vector,deque等数组实现的容器)
Functional 比较方式
*/
priority_queue<Type, Container, Functional> //实例
//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q; //greater和less是std实现的两个仿函数(就是使一个类的使用看上去像一个函数。其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了)
最新文章
- Spring+SpringMvc+Mybatis框架集成搭建教程二(依赖配置及框架整合)
- Pyqt 控件的信号槽事件定义方法
- Javascript轮播 支持平滑和渐隐两种效果(可以只有两张图)
- fsn文件解析(C#)
- NCPC 2015 October 10, 2015 Problem D
- 312.	Burst Balloons
- Apache配置虚拟主机后,不能访问localhost的问题
- ●UOJ 34 多项式乘法
- SQL SERVER 2008远程数据库移植到本地的方法
- [Swift]LeetCode346. 从数据流中移动平均值 $ Moving Average from Data Stream
- 解决解决httpd: Could not reliably determine the server&#39;s fully qualified domain name
- lemon special judge模板
- spring boot(十一):Spring boot中mongodb的使用
- Android Studio导入系统 jar包,编译时优先于查找系统SDK
- JavaScript中this的用法 及 如何改变this的指向
- file 文件上传后缀转化小写
- 使用Swashbuckle.AspNetCore生成.NetCore WEBAPI的接口文档
- C#操作Sqlite快速入门及相关工具收集
- 数组元素的移动(删除) C#实现
- Scrum Meeting 11.10
热门文章
- AndroidStudio 编译失败;Caused by: org.gradle.api.resources.ResourceException: Could not get resource..
- 微信小程序入门基础
- Linux上的Systemctl命令
- Redis SDS 深入一点,看到更多!
- 【部分】Asp.Net Mvc 控制器与视图的数据传递
- 一.vue 初识
- actuator与spring-boot-admin 可以说的秘密
- React源码之组件的实现与首次渲染
- suprious weakup
- Python 之父说 Python 历史