STL容器使用DEMO-priority_queue
来源:互联网 发布:淘宝首页是静态页面吗 编辑:程序博客网 时间:2024/06/07 03:27
- //////////////////////////////////////////////////////////////////////////
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/08/24
- // Describe: STL priority_queue 使用DEMO
- //////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <Windows.h>
- using namespace std;
- // 队列元素
- template <class T>
- class PriorityMessage
- {
- public:
- PriorityMessage(int priority, T objMessage): m_nPriority(priority), m_objMessage(objMessage)
- {
- LARGE_INTEGER liValue;
- ::QueryPerformanceCounter(&liValue);
- m_tInQueue = liValue.LowPart;
- }
- ~PriorityMessage()
- {
- }
- public:
- int m_nPriority;
- unsigned long m_tInQueue;
- T m_objMessage;
- };
- // 比较器
- template <class _Ty>
- struct PMessageCmp: public binary_function<_Ty, _Ty, bool>
- {
- bool operator()(const PriorityMessage<_Ty>& _Left, const PriorityMessage<_Ty>& _Right) const
- {
- if (_Left.m_nPriority != _Right.m_nPriority)
- {
- return _Left.m_nPriority < _Right.m_nPriority;
- }
- else
- {
- return _Left.m_tInQueue < _Right.m_tInQueue;
- }
- }
- };
- typedef PriorityMessage<string> STR_PM;
- typedef priority_queue<STR_PM, vector<STR_PM>, PMessageCmp<string> > STR_PMQ;
- void main(void)
- {
- STR_PMQ pmqStr;
- // 插入优先队列
- pmqStr.push(STR_PM(1, "level11"));
- pmqStr.push(STR_PM(3, "level31"));
- pmqStr.push(STR_PM(1, "level12"));
- pmqStr.push(STR_PM(2, "level21"));
- pmqStr.push(STR_PM(3, "level32"));
- pmqStr.push(STR_PM(4, "level41"));
- pmqStr.push(STR_PM(5, "level51"));
- pmqStr.push(STR_PM(2, "level23"));
- pmqStr.push(STR_PM(4, "level42"));
- pmqStr.push(STR_PM(1, "level13"));
- pmqStr.push(STR_PM(2, "level24"));
- pmqStr.push(STR_PM(4, "level43"));
- pmqStr.push(STR_PM(4, "level44"));
- // 打印优先队列
- while (!pmqStr.empty())
- {
- STR_PM& pmStr = pmqStr.top(); // 获取头部元素
- cout << "[LEVEL: " << pmStr.m_nPriority << "] "
- << "[QUEUE TIME: " << pmStr.m_tInQueue << "] "
- << "[MESSAGE: " << pmStr.m_objMessage.c_str() << "] " << endl;
- pmqStr.pop();
- }
- system("pause");
- }
- STL容器使用DEMO-priority_queue
- STL容器适配器:priority_queue
- STL容器使用DEMO-vector
- STL容器使用DEMO-deque
- STL容器使用DEMO-list
- STL容器使用DEMO-map
- STL容器使用DEMO-multimap
- STL容器使用DEMO-set
- STL容器使用DEMO-multiset
- STL容器使用DEMO-stack
- STL容器使用DEMO-queue
- STL容器使用DEMO-valarray
- STL容器使用DEMO-bitset
- STL 容器 priority_queue(优先队列)
- STL 容器之 priority_queue小结
- 【STL】顺序容器 — priority_queue
- [C++]STL容器之priority_queue
- STL priority_queue使用
- STL容器使用DEMO-valarray
- S3C2440时钟详细描述
- STL容器使用DEMO-bitset
- REFCNT
- [转]四行代码算大数阶乘(绝对强悍,毫秒级别的)
- STL容器使用DEMO-priority_queue
- 呵呵
- AB交换问题
- 对象锁
- CONFIG_SYS_CLK_FREQ
- COME ON~
- SQL代码自动生成器
- 学习 ARM 系列 -- FS2410 开发板上启用 MMU 实现虚拟内存管理
- 我的数据结果课程设计题目