cpp的stl的队列和栈
来源:互联网 发布:广告智能推送人工智能 编辑:程序博客网 时间:2024/05/18 01:16
cpp的stl的队列和栈
stl的queue和stack除了第二个参数,可以指定采用哪个集合存储数据,其他的看代码即可了解
//// main.cpp// use_stack_queue//// Created by bikang on 16/11/1.// Copyright (c) 2016年 bikang. All rights reserved.//#include <iostream>#include <vector>#include <queue>#include <stack>#include <list>using namespace std;void tstack();void tqueue();int main(int argc, const char * argv[]) { //tstack(); tqueue(); return 0;}void tstack(){ //stack处理 stack<int> ps; for(int i=0;i<10;++i)ps.push(i); cout << ps.size() << endl; cout << ps.top() << endl; ps.pop(); cout << ps.top() << endl; //第二个参数表示用什么来存储数据 stack<int, vector<int>> ps2;}void tqueue(){ cout << "test"<<endl; queue<int,list<int>> q1; for(int i=0;i<10;++i)q1.push(i); cout << q1.size() <<endl; cout << q1.front() << " " << q1.back() << endl; q1.pop(); cout << q1.front() << " " << q1.back() << endl; //优先堆 priority_queue<int> p1; p1.push(31); p1.push(2); p1.push(32); p1.push(18); cout << p1.size()<< endl; while (!p1.empty()) { cout << p1.top()<<","; p1.pop(); } cout << endl; //使用谓词从小到大排序 priority_queue<int,vector<int>,greater<int>> p2; p2.push(31); p2.push(2); p2.push(32); p2.push(18); cout << p2.size()<< endl; while (!p2.empty()) { cout << p2.top()<<","; p2.pop(); } cout << endl;}
0 0
- cpp的stl的队列和栈
- cpp的STL值vector和deque
- STL队列和栈的简单运用
- C++ STL 栈和队列的使用
- 【C++】STL队列和栈的使用
- STL中栈和队列的使用方法
- C++ STL栈和队列的使用
- STL中栈和队列的使用方法
- C++ STL栈和队列的使用
- STL 中栈和队列的使用方法
- Cpp--STL的组成
- cpp的STL算法
- STL中栈、队列和优先队列的使用
- STL 优先队列、队列、栈的使用
- STL 优先队列、队列、栈的用法
- STL优先队列,队列,栈的使用
- STL 优先队列、队列、栈的使用
- stl 栈 队列的用法
- Java关于周跨年的周数计算
- c#文件拷贝和删除
- getch( )与ungetch( )两个函数有什么用途呢?
- jQuery处理滚动事件
- SWPU 2016 web 部分思路整理
- cpp的stl的队列和栈
- Xubuntu15.04安装opencv3.1并测试
- git学习的地址
- hdu5934Bomb
- 友盟分享:问题总结 1 调起微信/微博界面时一闪而过,无法弹出确认分享界面
- 从文件中或控制台每次读取一个单词或一行
- IOS Javascript Date的坑
- 算法导论之最大流
- Linux电源管理-wakeup count