欢迎来到天天文库
浏览记录
ID:34435763
大小:281.67 KB
页数:8页
时间:2019-03-06
《优先队列变优先级》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、优先队列默认情况下是按从大到小排列的:////默认情况,按从大到小排列#include#includeusingnamespacestd;intmain(){intnum[10]={14,10,56,7,83,22,36,91,3,47};priority_queueq;for(inti=0;i<=9;i++){q.push(num[i]);}cout<<"默认情况:"<2、<<"";q.pop();}cout<#include#include//#includeusingnamespacestd;intmain(){intnum[10]={14,10,56,7,83,22,36,91,3,47};priori3、ty_queue,greater>que;/////采取最小优先策略,即按从小到大的顺序排列priority_queue,less>que1;////采取最大优先策略,即按从大到小的顺序排列for(inti=0;i<=9;i++){que.push(num[i]);que1.push(num[i]);}cout<<"greater:"<4、p();cout<:"<#includ5、e#include//#includeusingnamespacestd;intmain(){floatnum[10]={14.2,10.1,56.1,7.1,83.1,22.2,36.1,91.2,3.1,47.2};priority_queue,greater>que;/////采取最小优先策略,即按从小到大的顺序排列priority_queue,less6、>que1;////采取最大优先策略,即按从大到小的顺序排列for(inti=0;i<=9;i++){que.push(num[i]);que1.push(num[i]);}cout<<"greater:"<:"<7、1.top();cout<#include#includeusingnamespacestd;structstudent{stringname;floatscore8、;/////重载<运算符来实现改变优先规则booloperator<(conststudent&s)const{//////按score由小到大排列returns.scorescore;}};intmain(){priority_queuepq;studentstu;stu.name="lixiang";stu.score=80.0;pq.push(stu
2、<<"";q.pop();}cout<#include#include//#includeusingnamespacestd;intmain(){intnum[10]={14,10,56,7,83,22,36,91,3,47};priori
3、ty_queue,greater>que;/////采取最小优先策略,即按从小到大的顺序排列priority_queue,less>que1;////采取最大优先策略,即按从大到小的顺序排列for(inti=0;i<=9;i++){que.push(num[i]);que1.push(num[i]);}cout<<"greater:"<4、p();cout<:"<#includ5、e#include//#includeusingnamespacestd;intmain(){floatnum[10]={14.2,10.1,56.1,7.1,83.1,22.2,36.1,91.2,3.1,47.2};priority_queue,greater>que;/////采取最小优先策略,即按从小到大的顺序排列priority_queue,less6、>que1;////采取最大优先策略,即按从大到小的顺序排列for(inti=0;i<=9;i++){que.push(num[i]);que1.push(num[i]);}cout<<"greater:"<:"<7、1.top();cout<#include#includeusingnamespacestd;structstudent{stringname;floatscore8、;/////重载<运算符来实现改变优先规则booloperator<(conststudent&s)const{//////按score由小到大排列returns.scorescore;}};intmain(){priority_queuepq;studentstu;stu.name="lixiang";stu.score=80.0;pq.push(stu
4、p();cout<:"<#includ
5、e#include//#includeusingnamespacestd;intmain(){floatnum[10]={14.2,10.1,56.1,7.1,83.1,22.2,36.1,91.2,3.1,47.2};priority_queue,greater>que;/////采取最小优先策略,即按从小到大的顺序排列priority_queue,less
6、>que1;////采取最大优先策略,即按从大到小的顺序排列for(inti=0;i<=9;i++){que.push(num[i]);que1.push(num[i]);}cout<<"greater:"<:"<7、1.top();cout<#include#includeusingnamespacestd;structstudent{stringname;floatscore8、;/////重载<运算符来实现改变优先规则booloperator<(conststudent&s)const{//////按score由小到大排列returns.scorescore;}};intmain(){priority_queuepq;studentstu;stu.name="lixiang";stu.score=80.0;pq.push(stu
7、1.top();cout<#include#includeusingnamespacestd;structstudent{stringname;floatscore
8、;/////重载<运算符来实现改变优先规则booloperator<(conststudent&s)const{//////按score由小到大排列returns.scorescore;}};intmain(){priority_queuepq;studentstu;stu.name="lixiang";stu.score=80.0;pq.push(stu
此文档下载收益归作者所有