容器适配器之stack
参见http://www.cplusplus.com/reference/stack/stack/
template<class T, class Container = deque<T>> class stack;
LIFO stack
Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.
[堆栈(stack)是一种容器适配器,具有后进先出的结构元素的插入和提取都只在容器的一端进行]
stacks are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed/popped from the "back" of the specific container, which is known as the top of the stack.
[容器适配器是一个类,这个类使用一个特定的容器类对象作为它的内在容器,该内在容器提供了一系列的成员函数来读取它的元素]
The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall support the following operations:
[堆栈的内在容器可以是一个标准容器类模板或者其他专门设计的容器类,但无论如何,内在容器都应该支持以下几种操作:]
empty
size
back
push_back
pop_back
The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a particular stack class instantiation, the standard container deque is used.
[标准容器类vector、deque和list都满足这些要求。默认的内在容器是deque]
/*
//construct stack
stack (const container_type& ctnr = container_type()); ctnr
Container object.
[ctnr是一个容器类对象]
container_type is the type of the underlying container type (defined as an alias of the second class template parameter, Container; see member types).
[ctnr的数据类型container_type是内在容器的数据类型,即第二个模板参数Container] A container adaptor keeps internally a container object as data. This container object is a copy of the ctnr argument passed to the constructor, if any, otherwise it is an empty container.
[stack会将一个容器对象作为数据,这个容器对象是传递到构造函数中的参数ctnr,如果没有传递参数ctnr则为空容器]
*/
#include <iostream>
#include <stack>
#include <vector>
#include <deque> int main()
{
std::deque<int> mydeque(, );
std::vector<int> myvector(, ); std::stack<int> first; // empty stack with deque as underlying container
std::stack<int> second(mydeque); // stack initialized to copy of deque with deque as underlying container std::stack<int, std::vector<int>> third; //empty stack with vector as underlying container
std::stack<int, std::vector<int>> fourth(myvector); //statck initialized to copy of vector with vector as underlying container std::cout << "size of first: " << first.size() << '\n';
std::cout << "size of second: " << second.size() << '\n';
std::cout << "size of third: " << third.size() << '\n';
std::cout << "size of fourth: " << fourth.size() << '\n'; system("pause");
return ;
}
/*
bool empty() const;
size_type size() const;
void push(const value_type& val);
void pop();
value_type& top();
*/
#include <iostream>
#include <stack> int main()
{
std::stack<int> mystack; for(int i=; i<; i++)
mystack.push(i*); std::cout<<"mystack containes: ";
while(!mystack.empty())
{
std::cout<<mystack.top()<<' ';
mystack.pop();
} std::cout<<'\n'; system("pause");
return ;
}
容器适配器之stack的更多相关文章
- C++STL模板库适配器之stack容器
目录 适配器 一丶适配器简介 二丶栈(stack)用法 1.栈的常用方法 适配器 一丶适配器简介 Stl中的适配器,有栈 (stack) 队列 queue 根priority_queue 适配器都是包 ...
- 容器适配器之priority_queue
template <class T, class Container = vector<T>, class Compare = less<type ...
- 容器适配器之queue
转载http://blog.csdn.net/thefutureisour/article/details/7751846容器适配器容器适配器其实就是一个接口转换装置,使得我们能用特定的方法去操作一些 ...
- C++STL模板库适配器之queue队列
目录 适配器之队列 一丶队列简介 二丶队列(queue)代码操作 1.常用方法 适配器之队列 一丶队列简介 队列是先进先出的数据结构. 在STL中使用 queue表示. 底层使用的是序列容器deque ...
- C++STL模板库适配器之优先级队列
目录 适配器之优先级队列 一丶优先级队列简介(priority_queue) 二丶优先级队列代码演示 1.优先级队列代码以及使用简介 适配器之优先级队列 一丶优先级队列简介(priority_queu ...
- 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...
- stl容器学习——queue,stack,list与string
目录 头文件 string 目录部分 1.string的定义及初始化 ① 用一个字符串给另一个字符串赋值 ②用字符串常量对字符串进行赋值 ③ 用n个相同的字符对字符串赋值 2.string的运算符及比 ...
- C++ STL容器之 stack
STL 中的 stack 是一种容器适配器,而不是一种容器. 它是容器适配器是指,只要支持一系列方法的容器(empty, size, back, push_back, pop_back),都能作为st ...
- C++容器简介1—stack
一.简介 stack是一种容器适配器(STL的容器分为顺序容器和关联容器,容器适配器),被设计来用于操作先进后出(FILO)结构的情景,在这种情况下, 元素的插入和删除都只能在容器的尾部进行. sta ...
随机推荐
- 使用cnpm搭建企业内部私有NPM仓库
cnpm是企业内部搭建npm镜像和私有npm仓库的开源方案.它同时解决了现有npm架构的一些问题. 为什么企业需要私有NPM 主要有如下理由: 确保npm服务快速.稳定:对于企业来说,上线生产系统的时 ...
- LINE最新版6.5.0在iOS上的删除信息取证
iOS: 9.3.2版 LINE: 6.5.0版 取出LINE的数据库 Line.sqlite,路径如下所示: 检视删除的信息,发现还有不少残留,虽然都是片段,但拼拼凑凑总还是能有些蛛丝马迹,毕竟,总 ...
- Android IOS WebRTC 音视频开发总结(十二)-- sufaceview
谈到音视频不得不谈谈对视频呈现的理解,为了让大家能有一个更好的理解,先看看android里面SurfaceView的原理,后续陆续分享其绘画原理. 说明:本文是转载的,转载自哪里我也不知道,貌似经过很 ...
- 乐够GO应用源码完整版
乐够GO应用源码完整版 V1.0,系统2.3以上使用,需要联网,每天定时更新数据,实现了对文章赞的功能,以及常用的评论功能,还有生活的职业的相关功能,如查找功能,分类的分类等功能,具体大家可以看看应用 ...
- 介绍一点.NET反编译的知识
反编译是我们理解.NET内部实现的一种良好的手段. 程序编译时 Test.exe是IL代码.我们可以通过一些工具,来查看这些IL代码. 一模一样? 理论上来说,一模一样的反编译是不存在的.原因有以下3 ...
- 软件工程 speedsnail 冲刺5
2015-5-9 完成任务:学习了黑马android教学视频10\11\12集,填写游戏人的姓名功能为明天的记分板准备: 遇到问题: 问题1 Suspicious method call; shoul ...
- 一些peoplecode小技巧【一】
1. Get the description of the translate value: No need to write SQLEXEC on PSXLATITEM passing fieldn ...
- SQL SERVER中查询参数为空(null)时默认查询所有的实现
最近在项目中碰到一个比较有意思的问题,网上查找了一些方法,在这里总结分享一下. 我们经常会碰到这样的场景:需要查询数据,有一些查询条件,但是查询的时候,我们希望在某个条件为空的时候,则不筛选这个条件, ...
- 常见的HTTP错误总结
一般来说HTTP2XX,代表请求正常完成,HTTP3XX代表网站重定向,HTTP4XX,代表客户端出现错误,HTTP5XX,代服务器端出现了错误 HTTP301:请求的数据具有新的位置 HTTP302 ...
- SequoiaDB创始人:比MongoDB领先一到两年 打造企业级NoSQL数据库
CSDN.NET 这几年来, NoSQL数据库凭借其易扩展.高性能.高可用.数据模型灵活等特色吸引到了大量新兴互联网公司的青睐,包括国内的淘宝.新浪.京东商城.360.搜狗等都已经在局部尝试NoS ...