STL之priority_queue
下面以 long long 型队列介绍: Q.empty() // 判断队列是否为空 返回ture表示空 返回false表示空 bool
Q.top() // 返回顶端元素的值 元素还在队列里 long long
Q.pop() // 删除顶端元素 void
Q.push(V) // 把 long long型的数V加入到队列里 它会制动条件V的位置 void
Q.size() // 返回队列里元素个数 unsigned int priority_queue<int,vector<int>,greater<int> > que; // 最小优先队列
priority_queue<int> que1; // 最大优先队列
priority_queue<int,vector<int>,less<int> > que1; // 最大优先队列 ( 注意在两个尖括号之间一定要留空格。)
priority_queue<node>que; // 结构体node自己定义 是其它类型的如long long 用最小优先队列需要从载 cmp 类 struct cmp{ // 整形最小优先队列
bool operator()(const int i,const int j){
return i>j;
}
};
priority_queue<int,vector<int>,cmp>que; struct cmp{ // long long 型最小优先队列
bool operator()(const long long i,const long long j){
return i>j;
}
};
priority_queue<int,vector<long long>,cmp> Q; struct cmp{ // string表示整数最小最优队列的重载
bool operator()(const string &i,const string &j){
int len1=i.length(),len2=j.length();
if(len1==len2)return i.compare(j)>;
return len1>len2;
}
};
priority_queue<int,vector<string>,cmp> Q; bool cmpe(string i,string j){ // 从大数到小数的排序重载
int len1=i.length(),len2=j.length();
if(len1==len2)return i.compare(j)>;
return len1 > len2;
}
sort(a+,a++,cmpe);
STL之priority_queue的更多相关文章
- STL之priority_queue(优先队列)
priority_queue是一个容器适配器,在这个容器里第一个数据元素是最大的.它的使用场景是什么样:如果12306抢票,为什么黄牛能抢这么多票,感觉12306那边的请求队列是一个优先队列,黄牛的请 ...
- STL中priority_queue小结
(1)为了运用priority_queue,你必须包含头文件<queue>:#include<queue> (2)在头文件中priority_queue定义如下: namesp ...
- C++ STL之priority_queue
STL中的priority_queue(优先队列)是一种会按照自定义的一种方式(数据的优先级)来对队列中的数据进行动态的排序的容器,不同优先级的情况下,top()上永远是最高优先级的数据,其底层采用的 ...
- STL之priority_queue使用简介
优先队列容器也是一种从一端入队,另一端出对的队列.不同于一般队列的是,队列中最大的元素总是位于队首位置,因此,元素的出对并非按照先进先出的要求,将最先入队的元素出对,而是将当前队列中的最大元素出对. ...
- STL 中priority_queue小结
(1)为了运用priority_queue,你必须包含头文件<queue>:#include<queue> (2)在头文件中priority_queue定义如下: nam ...
- 【转载】STL之priority_queue
参考资料:传送门先回顾队列的定义:队列(queue)维护了一组对象,进入队列的对象被放置在尾部,下一个被取出的元素则取自队列的首部.priority_queue特别之处在于,允许用户为队列中存储的元素 ...
- 【STL】-priority_queue的用法
初始化: priority_queue<int> maxPQ; priority_queue<int,vector<int& ...
- STL之priority_queue为复合结构排序
priority_queue为复合结构排序: #include <iostream> #include <queue> using namespace std; struct ...
- C++ STL 优先队列 priority_queue 详解(转)
转自https://blog.csdn.net/c20182030/article/details/70757660,感谢大佬. 优先队列 引入 优先队列是一种特殊的队列,在学习堆排序的时候就有所了解 ...
随机推荐
- php备份mysql的代码
1. mydb.php //DB类2. backup.php //备份脚本3. restore.php //还原脚本 mydb.php <?class db{ var $linkid;var $ ...
- lua相关笔记
--[[ xpcall( 调用函数, 错误捕获函数 ); lua提供了xpcall来捕获异常 xpcall接受两个参数:调用函数.错误处理函数. 当错误发生时,Lua会在栈释放以前调用错误处理函数,因 ...
- linux系统的初化始配置
一.网络的初始化 1.ip地址的修改(临时生效) 使用ifconfig命令 ifconfig 网卡名 ip地址 子网掩码 [root@localhost /]# ifconfig eno1677773 ...
- 关于控件的Invoke(...)方法和BeginInvoke(...)方法的区别
这两个方法最主要的区别就是一个是同步,一个是异步,即会阻塞线程,那么阻塞哪个线程呢?我们用代码来分析(工具是VS2010) using System; using System.Collections ...
- Lintcode 166. 链表倒数第n个节点
----------------------------------- 最开始的想法是先计算出链表的长度length,然后再从头走 length-n 步即是需要的位置了. AC代码: /** * De ...
- head标签详细讲解
head标签详细讲解 head位于html网页的头部,后前的标签,并以开始以结束的一html标签. Head标签位置如图: head标签示意图 head包含标签 meta,title,link,bas ...
- 病毒四度升级:安天AVL Team揭露一例跨期两年的电信诈骗进化史
自2014年9月起,安天AVL移动安全团队持续检测到一类基于Android移动平台的间谍类病毒,病毒样本大多伪装成名为"最高人民检察院"的应用.经过反编译逆向分析以及长期的跟踪调查 ...
- 使用Selector改变TextView的字体颜色textColor的方法
先上Selector文件,名字为singer_fragment_top_text_style.xml, <?xml version="1.0" encoding=" ...
- 新浪云SAE搭建python环境 问题拾遗
1.python程序部署到sae上需要做的改动 在线上需要转换成wsgi的形式运行python程序. sae中运行python程序需要指定一个函数为入口函数. application = sae.cr ...
- xplan.sql(本脚本获取执行计划显示执行顺序)
-- ---------------------------------------------------------------------------------------------- -- ...