priority_queue::push();pop(),empty,back(),front();size()
来源:互联网 发布:淘宝买cs积分可以干嘛 编辑:程序博客网 时间:2024/06/09 01:43
下面的代码示例阐释了如何使用 Visual c + + 中的 priority_queue::push、 priority_queue::pop、 priority_queue::empty、 priority_queue::top,和 priority_queue::size STL 函数。
priority_queue 适配器包含支持该 priority_queue 的容器的类型定义类型的对象。支持的两个容器都是向量并在 deque。对象插入的 push (),并且 pop() 被删除。top() 返回该 priority_queue 顶部的项目。
由于适配器不支持迭代,一个 priority_queue 有没有相关联的迭代器。
Priority_queue 允许您维护的项由一个相关联的比较器功能的比如小于,大于,等的已排序的集合。因此,顶部的项目将成为的最小或最高基于所选函数的选择候选。
priority_queue::push();
priority_queue::pop();
priority_queue::empty();
priority_queue::top();
priority_queue::size();
// Compile options needed: /GX// // <filename> : priority_queue.cpp// // Functions:// // priority_queue::push(), priority_queue::pop(),// priority_queue::empty(), priority_queue::top(), queue::size()// // Written by Debabrata Sarma// of Microsoft Product Support Services,// Copyright (c) 1996 Microsoft Corporation. All rights reserved.////////////////////////////////////////////////////////////////////// #include <iostream>#include <queue>#include <deque>#include <vector>#include <functional>using namespace std;#if _MSC_VER > 1020 // if VC++ version is > 4.2 using namespace std; // std c++ libs implemented in std #endif// Using priority_queue with deque// Use of function greater sorts the items in ascending ordertypedef deque<int, allocator<int> > INTDQU;typedef priority_queue<int,INTDQU, greater<int> > INTPRQUE;// Using priority_queue with vector// Use of function less sorts the items in descending ordertypedef vector<char, allocator<char> > CHVECTOR;typedef priority_queue<char,CHVECTOR,less<char> > CHPRQUE;void main(void){ int size_q; INTPRQUE q; CHPRQUE p; // Insert items in the priority_queue(uses deque) q.push(42); q.push(100); q.push(49); q.push(201); // Output the item at the top using top() cout << q.top() << endl; // Output the size of priority_queue size_q = q.size(); cout << "size of q is:" << size_q << endl; // Output items in priority_queue using top() // and use pop() to get to next item until // priority_queue is empty while (!q.empty()) { cout << q.top() << endl; q.pop(); }// Insert items in the priority_queue(uses vector) p.push('c'); p.push('a'); p.push('d'); p.push('m'); p.push('h'); // Output the item at the top using top() cout << p.top() << endl; // Output the size of priority_queue size_q = p.size(); cout << "size of p is:" << size_q << endl; // Output items in priority_queue using top() // and use pop() to get to next item until // priority_queue is empty while (!p.empty()) { cout << p.top() << endl; p.pop(); }}程序输出:42q 的大小是: 44249100201mp 的大小是: 5mhdc
- priority_queue::push();pop(),empty,back(),front();size()
- 编写一个类,实现简单的栈操作。数据的操作按先进后出的顺序。成员函数为pop; push; size; full; empty; print等等
- 栈程序演示(init,push,pop,clear,empty,traverse)
- PUSH/POP
- front(), back() demo
- 自定义stack类模版,实现empty?full?push,pop,gettop,clear,display
- front/back与begin/end
- 数据传输指令--push、pop
- GCC push/pop说明
- push和pop
- 堆栈初始化,POP,PUSH()
- push和pop
- ios push pop动画
- 导航控制器push/pop
- [iOS_Dev] pop / push modal
- NavigationViewControler pop/push
- Push,Pop,Modal,Dismiss
- #类模板# push,pop
- 关于Google的一些收集
- 企业架构(企业级架构)和应用程序架构
- alter system switch logfile和alter system archive log current 的区别
- ORACLE LOB 大对象处理
- Microsoft Office SharePoint Server 2007与Windows SharePoint Services 3.0的区别(WSS V3和MOSS2007的区别 )
- priority_queue::push();pop(),empty,back(),front();size()
- 快速计算正弦波
- 暴风影音因 “肥胖症” 公开道歉,中国客户端软件面临囚徒困境,说明了什么?
- ORA-29701 :unable to connect to Cluster Manager
- 如何安装MATLAB工具箱
- Oracle Rowid 介绍
- Ice Cream Sandwich系统将统一Android版本
- 走进javascript的世界 成都传智播客
- 女生爱问的几个问题之标准答案