优先队列的一些使用
来源:互联网 发布:钓鱼源码 编辑:程序博客网 时间:2024/06/05 23:01
#include<bits/stdc++.h>using namespace std;struct cmp1{ bool operator ()(int &a,int &b){ return a<b;//最小值优先 }};struct NODE { int x; bool operator < (const NODE &a) const { return x>a.x; }}num[7]={0,1234,23,12,14,555,632};struct NODE2 { int x,y; bool operator < (const NODE2 &a) const { if(x==a.x) return y<a.y; else return x<a.x; }};int main(){ int a[7]={0,1234,23,12,14,555,632}; //优先队列默认排升序,从最后一个出 priority_queue<int> q; //默认最大值优先 priority_queue<int,vector<int>,greater<int> > q1; //注意> >中要有空格 最小值优先 priority_queue<int,vector<int>,less<int> > q2; //最大值优先 priority_queue<int,vector<int>,cmp1> q3; //自定义比较 priority_queue<NODE> qn1; //自定义的结构 priority_queue<NODE2> qn2; //自定义的结构 for(int i=0;i<7;i++) q.push(a[i]); while(!q.empty()) { cout << q.top() << " "; q.pop(); } cout << endl; for(int i=0;i<7;i++) q1.push(a[i]); while(!q1.empty()) { cout << q1.top() << " "; q1.pop(); } cout << endl; for(int i=0;i<7;i++) q2.push(a[i]); while(!q2.empty()) { cout << q2.top() << " "; q2.pop(); } cout << endl; for(int i=0;i<7;i++) q3.push(a[i]); while(!q3.empty()) { cout << q3.top() << " "; q3.pop(); } cout << endl; for(int i=0;i<7;i++) qn1.push(num[i]); while(!qn1.empty()) { cout << qn1.top().x << " "; qn1.pop(); } NODE2 num2[7]; num2[0].x=9; num2[1].x=92; num2[2].x=23; num2[3].x=23; num2[0].y=11; num2[1].y=2; num2[2].y=112;num2[3].y=124; num2[4].x=9; num2[5].x=41; num2[6].x=9; num2[4].y=1222;num2[5].y=11; num2[6].y=12; for(int i=0;i<7;i++) qn2.push(num2[i]); while(!qn2.empty()) { cout << qn2.top().x << " " << qn2.top().y << endl; qn2.pop(); } return 0;}
0 0
- 优先队列的一些使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 优先队列的使用
- 第5周-项目3-时间类(1)
- 单链表的基本操作
- 三角形2
- bzoj4402: Claris的剑
- notes on virtio-blk driver
- 优先队列的一些使用
- 最短路径问题 HDU 3790 双权最短路
- HDU 5651xiaoxin juju needs help 带模除法逆元+有重复元素的全排列值
- hdu4031 Atack(树状数组区间更新单点求值)
- 在企业内部分发 iOS 应用程序
- Android学习:数据持久化技术(一,File & SharePreference)
- 三角形3
- Java 设计模式-适配器模式
- poj 1664[dfs]