如何使用STL中的 队列?

xxjoyjn 2008-11-22 03:54:55
有朋友告诉我这样使用队列:

#include<list>
#include<queue>
using namespace std;
typedef list<int, allocator<int> > INTLIST;
typedef queue<int,INTLIST > INTQUEUE;

为什么不能直接这样一句:typedef queue<int> INTQUEUE;?????????
朋友为什么告诉我要是用这样两句:

typedef list<int, allocator<int> > INTLIST;
typedef queue<int,INTLIST > INTQUEUE;???????????????

请问,上述两句定义中的第二个参数各是什么含义?
谢谢!!
...全文
133 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxjoyjn 2008-11-23
  • 打赏
  • 举报
回复
thanks,hityct1!
hityct1 2008-11-22
  • 打赏
  • 举报
回复
看看queue的定义吧:
In their implementation in the C++ Standard Template Library, queues take two template parameters:
template < class T, class Container = deque<T> > class queue;

Where the template parameters have the following meanings:
T: Type of the elements.
Container: Type of the underlying container object used to store and access the elements.

那么:
typedef list <int, allocator <int> > INTLIST; //等价于typedef list<int> INTLIST;
typedef queue<int,INTLIST > INTQUEUE;
它的Container是个list;估计这么定义是因为要频繁插入和删除(包括对中间的数据)。

typedef queue<int> INTQUEUE;
它的Container是个deque;只适合对队列的两头进行插入和删除。
jieao111 2008-11-22
  • 打赏
  • 举报
回复
找本stl教材看看吧
Non_Recursive 2008-11-22
  • 打赏
  • 举报
回复
up
Rex_love_Burger 2008-11-22
  • 打赏
  • 举报
回复
msdn的下载区有stl中文指南下载,写得相当详细,建议你去下载一个!!
jakqigle 2008-11-22
  • 打赏
  • 举报
回复
建议看看msdn或者找stl使用指南之类资料。

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧