STL中stack和queue的用法
2011-06-13 16:19
579 查看
发现在平常的编码中,stack和queue用到的频率都非常高,自己写一个stack和queue又显得麻烦,今天特地研究如何使用STL中的stack和queue。研究的并不输入,只是一些简单用法而已。
下面附上我的stack和queue使用代码
ps:
在VS2010中按CTRL+F5的时候命令行一闪而过,并没有以前“请按任意键继续. . .”这样的提示了。
在网上查询,最后得出的解决方法是加入stdlib.h的头文件,如下所示:
然后在程序最后加上system("pause");,如果有return的话要写在return之前。如下所示:
还有一种解决命令行一闪而没 方法,请参考
http://hi.baidu.com/liuguoyuhot/blog/item/f58f64edffae4a2826979108.html
下面附上我的stack和queue使用代码
#include<iostream> #include<stack> #include<queue> #include<stdlib.h>//system("pause");需要用到 using namespace std; int main() { stack<int> s; queue<int> q; int arry[4]={1,2,3,4}; for(int i=0;i<4;i++) { s.push(arry[i]); q.push(arry[i]); } //输出栈中元素 cout<<"栈长度为:"<<s.size()<<endl; for(int i=0;i<4;i++) { cout<<s.top()<<" "; s.pop(); } cout<<endl; //输出队列中元素 cout<<"队列长度为:"<<q.size()<<endl; for(int i=0;i<4;i++) { cout<<q.front()<<" "; q.pop(); } cout<<endl; /*int i; cin>>i;*/ system("pause"); return 0; }
ps:
在VS2010中按CTRL+F5的时候命令行一闪而过,并没有以前“请按任意键继续. . .”这样的提示了。
在网上查询,最后得出的解决方法是加入stdlib.h的头文件,如下所示:
#include<stdlib.h>//system("pause");需要用到
然后在程序最后加上system("pause");,如果有return的话要写在return之前。如下所示:
system("pause"); return 0;
还有一种解决命令行一闪而没 方法,请参考
http://hi.baidu.com/liuguoyuhot/blog/item/f58f64edffae4a2826979108.html
相关文章推荐
- STL容器用法速查表:list,vector,stack,queue,deque,priority_queue,set,map
- STL中stack和queue的用法
- stl 顺序容器适配器之stack, priority_queue, queue用法
- stl 顺序容器适配器之stack, priority_queue, queue用法
- STL容器用法速查表:list,vector,stack,queue,deque,priority_queue,set,map
- STL中stack和queue的用法
- #include<queue> STL 用法
- C++标准库__std::deque(双端队列),std::queue(队列),std::stack(栈)__由stl的定义我们就可以看出 queue和stack都是基于deque实现的和常用接口
- C++ STL stack queue 的使用函数
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- c++ STL中栈stack的用法
- C++ STL/ (5) stack&queue
- Map、Set、List、Queue、Stack的特点与用法
- C++的STL模板set,multiset,map,multimap,deque,list,stack,queue和priority_queue
- STL学习之八:priority_queue用法示例
- STL 整理map、set、vector、list、stack、queue、deque、priority_queue
- STL priority_queue用法
- C++ STL--stack/queue 的使用方法
- STL--stack/queue的使用方法
- C++ STL--stack/queue 的使用方法