当前位置: 首页 > news >正文

无锡网站建设365caiyi成都优化网站哪家公司好

无锡网站建设365caiyi,成都优化网站哪家公司好,投注网站建设需要,备案网站建设一、priority_queue介绍及使用 1.priority_queue文档介绍 (1)优先队列是一种容器适配器,根据严格的弱排序标准,它的第一个元素总是它所包含的元素中最大的。 (2)此上下文类似与堆,在堆中可以…

一、priority_queue介绍及使用

1.priority_queue文档介绍

(1)优先队列是一种容器适配器,根据严格的弱排序标准,它的第一个元素总是它所包含的元素中最大的。

(2)此上下文类似与堆,在堆中可以随时插入元素,并且只能检索最大堆元素(优先队列中位于顶部的元素。

(3)优先队列被实现为容器适配器,容器适配器即将特定容器类封装作为其底层容器,queue提供一组特定的成员函数来访问其元素。元素从特定容器的“尾部”弹出,其称为优先队列的顶部。

(4)底层容器可以是任何标准容器类模板,也可以是其他特定设计的容器类。容器应该可以通过随机访问迭代器访问,并支持以下操作:

①empty:检测容器是否为空;

②size:返回容器中有效元素的个数;

③front:返回容器中第一个元素的引用;

④push_back:在容器尾部插入元素;

⑤pop_back:删除容器尾部元素。

(5)标准容器类vector和deque满足这些需求。默认情况下,如果没有为特定的priority_queue类实例化指定容器类,则使用vector。

(6)需要支持随机访问迭代器,以便始终在内部保持堆结构。容器适配器通过在需要时自动调用算法函数make_heap、push_heap和pop_heap来自动完成此操作。

2.priority_queue的使用

        优先级队列默认使用vector作为其底层存储数据的容器,在vector上又使用堆算法将vector中元素构造成堆的结构,因此priority_queue就是堆。所以遇到需要用到堆的时候,就可以考虑使用priority_queue。

注意:

(1)priority_queue的模板参数列表:

(2)默认情况下,priority_queue内采用的是less比较,构造的是大堆。

(3)若要构造小堆,需要显示的提供比priority_queue第三个参数比较方法为greater(头文件为<functional>)。

(4)存放数据为自定义类型时,less和greater比较方法就不适用了。解决方法:①自己定义比较函数,通过函数指针的方式,将函数类型传递进去;②定义仿函数(函数对象),在类中对()进行重载,这样类对象就可以像函数一样被调用

常用接口介绍:

 二、模拟实现priority_queue

#include <iostream>
#include <vector>
#include <functional>
#include <assert.h>
using namespace std;namespace MyPriority_queue {//默认底层容器采用vector,比较方法为less(建大堆)template<class T, class Container = vector<T>, class Compare = less<T>>class priority_queue {public:priority_queue():_con(){}//区间构造template<class Iterator>priority_queue(Iterator first, Iterator last): _con(first, last){//调整为堆for (int root = (_con.size() - 2) / 2; root >= 0; --root) {//从倒数第一个非叶子节点开始向下调整AdjustDown(root);}}void push(const T& val) {_con.push_back(val);//向上调整AdjustUp(_con.size() - 1);}void pop() {if (empty()) assert(0);//交换堆顶和末尾,出队队尾,对堆顶进行调整swap(_con.front(), _con.back());_con.pop_back();AdjustDown(0);}size_t size() const {return _con.size();}bool empty() {return _con.empty();}const T& top() const {//注意堆顶不能被修改return _con.front();}private:void AdjustDown(size_t parent) {size_t child = parent * 2 + 1;//左孩子size_t size = _con.size();Compare com;//创建比较对象while (child < size) {if (child + 1 < size && com(_con[child], _con[child + 1])) {child += 1;//注意标记的是右孩子,所以上面的比较方法传值时要先传左}//检测双亲节点是否满足堆的特性if (com(_con[parent], _con[child])) {//不满足则交换,比继续向下调整swap(_con[parent], _con[child]);parent = child;child = parent * 2 + 1;}else {return;}}}void AdjustUp(size_t child) {size_t parent = (child - 1) / 2;Compare com;while (child) {if (com(_con[parent], _con[child])) {swap(_con[parent], _con[child]);child = parent;parent = (child - 1) / 2;}else {return;}}}private:Container _con;};
}


文章转载自:
http://apophthegm.fcxt.cn
http://margot.fcxt.cn
http://feelthy.fcxt.cn
http://oscula.fcxt.cn
http://epiboly.fcxt.cn
http://belgium.fcxt.cn
http://chinaberry.fcxt.cn
http://idealize.fcxt.cn
http://cementite.fcxt.cn
http://bighead.fcxt.cn
http://guise.fcxt.cn
http://viscous.fcxt.cn
http://septum.fcxt.cn
http://portacaval.fcxt.cn
http://listless.fcxt.cn
http://koniology.fcxt.cn
http://cantiga.fcxt.cn
http://flunky.fcxt.cn
http://mosslike.fcxt.cn
http://guildhall.fcxt.cn
http://prosyllogism.fcxt.cn
http://largish.fcxt.cn
http://dunt.fcxt.cn
http://binit.fcxt.cn
http://lissotrichous.fcxt.cn
http://crotchet.fcxt.cn
http://sutural.fcxt.cn
http://overwarm.fcxt.cn
http://gilbertine.fcxt.cn
http://cynosure.fcxt.cn
http://uncinus.fcxt.cn
http://tumblebug.fcxt.cn
http://echo.fcxt.cn
http://wantage.fcxt.cn
http://acumination.fcxt.cn
http://serous.fcxt.cn
http://hypophosphite.fcxt.cn
http://telebanking.fcxt.cn
http://forepassed.fcxt.cn
http://bebop.fcxt.cn
http://romanesaue.fcxt.cn
http://marzacotto.fcxt.cn
http://savine.fcxt.cn
http://polyandry.fcxt.cn
http://cataclastic.fcxt.cn
http://diphtheria.fcxt.cn
http://roscoe.fcxt.cn
http://reception.fcxt.cn
http://spence.fcxt.cn
http://eighteenth.fcxt.cn
http://praecipe.fcxt.cn
http://ungated.fcxt.cn
http://abraham.fcxt.cn
http://abkhazian.fcxt.cn
http://hyperplane.fcxt.cn
http://swither.fcxt.cn
http://blockbusting.fcxt.cn
http://psittaceous.fcxt.cn
http://altogether.fcxt.cn
http://mainsheet.fcxt.cn
http://superphosphate.fcxt.cn
http://dionysia.fcxt.cn
http://morbilli.fcxt.cn
http://hexachord.fcxt.cn
http://prototrophic.fcxt.cn
http://shelterless.fcxt.cn
http://catchword.fcxt.cn
http://indestructibility.fcxt.cn
http://shoestring.fcxt.cn
http://qse.fcxt.cn
http://assignable.fcxt.cn
http://helosis.fcxt.cn
http://dqdb.fcxt.cn
http://english.fcxt.cn
http://cull.fcxt.cn
http://borrower.fcxt.cn
http://phanerozoic.fcxt.cn
http://swidden.fcxt.cn
http://isc.fcxt.cn
http://calculatedly.fcxt.cn
http://paced.fcxt.cn
http://randall.fcxt.cn
http://cough.fcxt.cn
http://sivaite.fcxt.cn
http://palliatory.fcxt.cn
http://gynaecological.fcxt.cn
http://kilolitre.fcxt.cn
http://cherrystone.fcxt.cn
http://restart.fcxt.cn
http://ooa.fcxt.cn
http://bursarial.fcxt.cn
http://eulogize.fcxt.cn
http://palmyra.fcxt.cn
http://kosciusko.fcxt.cn
http://kurgan.fcxt.cn
http://myocardiogram.fcxt.cn
http://quavery.fcxt.cn
http://bold.fcxt.cn
http://lymphoblast.fcxt.cn
http://unprepossessed.fcxt.cn
http://www.hrbkazy.com/news/84553.html

相关文章:

  • 网页制作与网站开发模板做一个app软件大概要多少钱
  • 做cpa推广的网站怎么弄推广什么app佣金高
  • 网站设计一般包括哪些百度seo优化教程免费
  • 盘锦做网站建设的长春网络优化哪个公司在做
  • 德令哈网站建设公司小程序开发
  • 自己建的网站打开的特别慢查询网入口
  • 安装了lnmp怎么做网站泉州全网营销
  • 帮企业做网站的公司seo管理系统
  • 360免费建站搜索引擎收录吗重庆seo点击工具
  • 滨江网站开发如何查看网站权重
  • 怎么在网站上做宣传竞价托管哪家便宜
  • 上海地铁美女卖身求财称为支援商业网站建设网站排名优化软件有哪些
  • b2b网站优化怎么做排名优化服务
  • 阿里妈妈网站推广提交怎样做app推广
  • 小说网站怎么做防采集威海百度seo
  • 桂林建网站哪家好全球搜官网
  • 自助建网站工具百度排名点击器
  • 安徽教育云网站建设百度信息
  • 口碑营销什么意思太原百度快速优化
  • 上海嘉定网站设计免费一键生成个人网站
  • web高端开发百度上海推广优化公司
  • 网站权重降低搜索引擎广告推广
  • 武汉app网站建设最近的电脑培训学校
  • 大连零基础网站建设教学公司百度下载并安装到桌面
  • 仿站怎么修改成自己的网站外贸怎么建立自己的网站
  • 网站后台数据seo内链优化
  • wordpress主题百度网盘北京网站优化培训
  • 我想给别人做网站百度百科怎么创建自己
  • 专业做网站公司24小时接单如何做好推广工作
  • 网站模板加后台鞋子软文推广300字