queue-的常见操作
来源:互联网 发布:拳皇咆哮源码 编辑:程序博客网 时间:2024/06/06 18:18
#include<iostream>#include <queue>#include <list>using namespace std;#if 0* 1.队列是一种容器适配器, 用于在FIFO上下文中进行操作, 其中元素从一段插入, 然后在另一端进行提取;* 2.队列实现为容器适配器, 使用特定容器类的封装对象作为其底层容器的类, 提供一些特定成员来访问其中的元素, 元素被推入特定容器的后面, 并且从容器的前面弹出;* 3.构造函数通常包括一下几种:* 1.explict queue(const container_type& ctnr)* 2.explict queue(container_type&& ctnr = container_type());* 3.template <class Alloc> explict queue(const Alloc& alloc);* 4.template <class Alloc> explict queue(const container_type& cntr, const Alloc& alloc);* 5.template <class Alloc> explict queue(container_type&& cntr, const Alloc &alloc);* 6.template <class Alloc> explict queue(const queue& X, const Alloc& alloc);* 7.template <class Alloc> explict queue(queue&& X, const Alloc& alloc);#endifint main(){ //construct object; deque<int> mydeque(3, 33); list<int> mylist(2, 11); queue<int> first; first.push(3); queue<int> second(mydeque); queue<int, list<int>> third; queue<int, list<int>> fourth(mylist); cout << "first.size: " << first.size() << endl; cout << "second.size: " << second .size() << endl; cout << "third size: " << third.size() << endl; cout << "fourth.size: " << fourth.size() << endl; //.back():用于返回当前队列的最后一个元素; // reference& back(); // const_reference& back() const; cout << "first.back: " << first.back() << endl;#if 1 //.front()用于返回第一个元素 //reference& front(); //const_reference& front() const; first.front() += first.back(); cout << "first.front: " << first.front() << endl; //.emplace(): template <class... args> void emplace(Args&&.. args) //用于在队列尾部添加一个新的元素; queue<string> myqueuestring; myqueuestring.emplace("this is a freshman"); myqueuestring.emplace("this is a oldman"); cout << "myqueuestring constains: "; while (!myqueuestring.empty()) { cout << myqueuestring.front() << " "; myqueuestring.pop(); } cout << endl; //.push用于在一段放入元素; //void push(const value_type& val); //void push(value_type&& val); myqueuestring.push("that is a no-name man"); //.size()用于返回队列里面元素的多少; //.swap():用于交换两个队列的值; queue<int> newfirst; newfirst.push(1); newfirst.push(2); newfirst.push(3); newfirst.push(4); newfirst.push(5); queue<int> newsecond; newsecond.push(5); newsecond.push(4); newsecond.push(3); newsecond.push(2); newsecond.push(1); cout << "newfirst contains: "; while (!newfirst.empty()) { cout << newfirst.front() << " "; newfirst.pop(); } cout << endl; cout << "newsecond contains: "; while (!newsecond.empty()) { cout << newsecond.front() << " "; newsecond.pop(); } cout << endl;#endif}
阅读全文
0 0
- queue-的常见操作
- queue操作
- STL中stack,queue的操作
- C# Windows Azure Queue的操作
- C# Windows Azure Queue的操作
- Windows Azure 系列-- Azure Queue的操作
- queue stack priority_queue的基本操作
- 常见的SREng操作
- 常见的数据库操作
- msde 的常见操作
- 常见的checkbox操作
- 常见的radioButton操作
- javascrip 常见的操作
- XML常见的操作
- poi 常见的操作
- 字符串的常见操作
- 字符串的常见操作
- 数组的常见操作
- char ch[10]={"yhping"}; char ch2[10]={'y','h','p','i','n','g'}; char *str = "yhping"; 区别是什么。
- 各种浏览器全屏模式的方法、属性和事件介绍
- LeetCode-Swap Nodes in Pairs
- 集合
- SpringMVC与页面交互的几种方法
- queue-的常见操作
- 在PyCharm 软件中设置你的项目 使用的Python版本
- leetcode
- 关于SVN汉化失败
- hdu1108 最小公倍数
- 2.6Java继承(抽象类,接口,final)
- bzoj 4424: Cf19E Fairy dfs
- Java设计模式——空对象模式(Null Object Pattern)
- 第二章