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

北京制作网站报价建自己的零售网站

北京制作网站报价,建自己的零售网站,企业内部管理系统网站建设,安徽建设工程建设信息网站priority_queue是一个拥有权重概念的queue#xff0c;允许底部加入新的元素#xff0c;头部删除旧的元素#xff0c;以及审视元素数值的操作priority_queue带有权重的概念#xff0c;即元素按照权重进行排列#xff0c;而不是按照插入队列的顺序进行排序。要求权值高者在前…priority_queue是一个拥有权重概念的queue允许底部加入新的元素头部删除旧的元素以及审视元素数值的操作priority_queue带有权重的概念即元素按照权重进行排列而不是按照插入队列的顺序进行排序。要求权值高者在前缺省情况下priority_queue使用max_heap完成而max_heap物理层面是基于vector逻辑层面表现像complate binary treemax_tree用于实现priority_queue的按照权值高低自动递增排序的特性priority_queue定义完整列表 priority_queue底层使用vector在加上堆的处理规则priority_queue不被归纳为容器 而是容器适配器 #include iostream #include vector#ifdef __STL_USE_EXCEPTIONS #define __STL_TRY try #define __STL_UNWIND(action) catch(...) { action; throw; } #else #define __STL_TRY #define __STL_UNWIND(action) #endiftemplate class T,class Sequence std::vectorT,class Compare std::lesstypename Sequence::value_type class priority_queue{ public:typedef typename Sequence::valuetype value_type;typedef typename Sequence::size_type size_type;typedef typename Sequence::reference reference;typedef typename Sequence::const_reference const_reference; protected:Sequence c; //底层容器Compare comp; //元素大小的比较标准 public:priority_queue() : c (){}explicit priority_queue(const Compare x) : c() ,comp(x){}//以下使用的make_heap()、push_heap()、pop_heap()都是泛型算法//注意 任意一个构造函数都立刻在底层容器内产生一个implicit representation heap//指代比较器templateclass InputIteratorpriority_queue(InputIterator first, InputIterator last,const Compare x):c(first,last),comp(x){std::make_heap(c.begin(),c.end(),comp);}//没有指代比较器templateclass InputIteratorpriority_queue(InputIterator first, InputIterator last):c(first,last){std::make_heap(c.begin(),c.end(),comp);}bool empty()const{return c.empty();}size_type size() const{return c.size();}const_reference top()const{return c.front();}void push(const value_type x){__STL_TRY{//push_heap 是泛型算法先利用底层的push_back()将新的元素推入末端再重新排列heapc.push_back(x);//push_heap 是泛型算法std::push_heap(c.begin(),c.end(),comp);}__STL_UNWIND(c.clear());}void pop(){__STL_TRY{//pop_heap是泛型算法从heap中取出一个元素并不是整整将这个元素弹出而是重排heap//需要使用底层vector的pop_back()取得被弹出的元素std::pop_heap(c.begin(),c.end(),comp);c.pop_back();}__STL_UNWIND(c.clear());}}; priority_queue没有迭代器 priority_queue的所有元素进出是有规则限制的只有queue的顶端元素(权值最高者)才可以被外界使用priority_queue不提供遍历的功能因此无迭代器 测试用例 #include iostream #include vector#ifdef __STL_USE_EXCEPTIONS #define __STL_TRY try #define __STL_UNWIND(action) catch(...) { action; throw; } #else #define __STL_TRY #define __STL_UNWIND(action) #endiftemplate class T,class Sequence std::vectorT,class Compare std::lesstypename Sequence::value_type class priority_queue{ public:typedef typename Sequence::value_type value_type;typedef typename Sequence::size_type size_type;typedef typename Sequence::reference reference;typedef typename Sequence::const_reference const_reference; protected:Sequence c; //底层容器Compare comp; //元素大小的比较标准 public:priority_queue() : c (){}explicit priority_queue(const Compare x) : c() ,comp(x){}//以下使用的make_heap()、push_heap()、pop_heap()都是泛型算法//注意 任意一个构造函数都立刻在底层容器内产生一个implicit representation heap//指代比较器templateclass InputIteratorpriority_queue(InputIterator first, InputIterator last,const Compare x):c(first,last),comp(x){std::make_heap(c.begin(),c.end(),comp);}//没有指代比较器templateclass InputIteratorpriority_queue(InputIterator first, InputIterator last):c(first,last){std::make_heap(c.begin(),c.end(),comp);}bool empty()const{return c.empty();}size_type size() const{return c.size();}const_reference top()const{return c.front();}void push(const value_type x){__STL_TRY{//push_heap 是泛型算法先利用底层的push_back()将新的元素推入末端再重新排列heapc.push_back(x);//push_heap 是泛型算法std::push_heap(c.begin(),c.end(),comp);}__STL_UNWIND(c.clear());}void pop(){__STL_TRY{//pop_heap是泛型算法从heap中取出一个元素并不是整整将这个元素弹出而是重排heap//需要使用底层vector的pop_back()取得被弹出的元素std::pop_heap(c.begin(),c.end(),comp);c.pop_back();}__STL_UNWIND(c.clear());} };int main(){int ia[9] {0,1,2,3,4,8,9,3,5};priority_queueintiqp(ia,ia9);std::cout iqp.size() std::endl; //9for (int i 0; i iqp.size(); i) {std::cout iqp.top() ; //9 9 9 9 9 9 9 9 9}std::cout std::endl;while(!iqp.empty()){std::cout iqp.top() ; //9 8 5 4 3 3 2 1 0iqp.pop();}std::cout std::endl; } 参考链接 __STL_TRY和__STL_UNWIND这两个宏的意思 - Superpig0501 - 博客园
http://www.zqtcl.cn/news/478685/

相关文章:

  • 中英网站怎么做网站域名的作用是什么
  • 网站建设开题报告ppt模板重庆建设工程信息网址
  • 做个什么类型网站百度云资源链接分享群组
  • 商务网站建设的主流程西安建设局网站
  • 邢台营销型网站建设做网站的保证承诺
  • 关于茶叶的网站模板免费下载wordpress多边形按钮
  • 贵阳市网站建设手工制作花
  • 娄底哪里做网站免费永久不限空间
  • 网站标签怎么做wordpress 后台模板
  • 内江移动网站建设网站内部链接的作用有哪些
  • 阿里云的wordpress建站wordpress 批量定时发布
  • 网站院长信箱怎么做海报设计制作网站
  • 办网站如何备案怎么制作微信链接网页
  • 聊城门户网站建设怎样能有个人网站
  • 营销网站建设资料创意网站 模板
  • 免费的短网址生成器深圳外贸网站优化
  • 网站推广哪个平台最好图库
  • 在东莞做网站vue做网站好吗
  • 手机网站的页面大小郑州恩恩网站建设
  • 视频运营管理平台长沙网站seo技术
  • 网站建设有哪些规章制度网页版面
  • 海伦网站建设做网站建设的联系电话
  • 免费做字体的网站枣强网站建设代理
  • 建设网站素材海南百度推广公司电话
  • 温州企业网站建设费用培训行业门户网站建设方案
  • 口碑好的常州网站优化深圳市光明区实验学校
  • 网站怎么做微博认证网页设计代码html作品展示
  • 在线网站建设活动初创企业的建站流程
  • 汨罗哪里有网站开发的公司电话百度首页关键词推广
  • 天津百度整站优化服务政务网站模版