参见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的更多相关文章

  1. C++STL模板库适配器之stack容器

    目录 适配器 一丶适配器简介 二丶栈(stack)用法 1.栈的常用方法 适配器 一丶适配器简介 Stl中的适配器,有栈 (stack) 队列 queue 根priority_queue 适配器都是包 ...

  2. 容器适配器之priority_queue

    template <class T, class Container = vector<T>,                class Compare = less<type ...

  3. 容器适配器之queue

    转载http://blog.csdn.net/thefutureisour/article/details/7751846容器适配器容器适配器其实就是一个接口转换装置,使得我们能用特定的方法去操作一些 ...

  4. C++STL模板库适配器之queue队列

    目录 适配器之队列 一丶队列简介 二丶队列(queue)代码操作 1.常用方法 适配器之队列 一丶队列简介 队列是先进先出的数据结构. 在STL中使用 queue表示. 底层使用的是序列容器deque ...

  5. C++STL模板库适配器之优先级队列

    目录 适配器之优先级队列 一丶优先级队列简介(priority_queue) 二丶优先级队列代码演示 1.优先级队列代码以及使用简介 适配器之优先级队列 一丶优先级队列简介(priority_queu ...

  6. 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例

    一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...

  7. stl容器学习——queue,stack,list与string

    目录 头文件 string 目录部分 1.string的定义及初始化 ① 用一个字符串给另一个字符串赋值 ②用字符串常量对字符串进行赋值 ③ 用n个相同的字符对字符串赋值 2.string的运算符及比 ...

  8. C++ STL容器之 stack

    STL 中的 stack 是一种容器适配器,而不是一种容器. 它是容器适配器是指,只要支持一系列方法的容器(empty, size, back, push_back, pop_back),都能作为st ...

  9. C++容器简介1—stack

    一.简介 stack是一种容器适配器(STL的容器分为顺序容器和关联容器,容器适配器),被设计来用于操作先进后出(FILO)结构的情景,在这种情况下, 元素的插入和删除都只能在容器的尾部进行. sta ...

随机推荐

  1. JS常用的设计模式(10)——模版方法模式

    模式方法是预先定义一组算法,先把算法的不变部分抽象到父类,再将另外一些可变的步骤延迟到子类去实现.听起来有点像工厂模式( 非前面说过的简单工厂模式 ). 最大的区别是,工厂模式的意图是根据子类的实现最 ...

  2. .NET Web开发总结

    在aspx文件中  创建控件 在右下角有控件信息 按类排序 会将控件信息安装类排序 点击控件 会增加属性页面的分页[事件]页面  可以增加其事件函数 字符串操作及其时间操作 fn_name.Inser ...

  3. linux device model简述

    参考: 1)<LINUX设备驱动程序>第十四章 Linux 设备模型 2)内核源码2.6.38 内核初始化的时候会对设备模型作初始化,见init/main.c: start_kernel- ...

  4. Ninject在mvc中的简单配置

    前言 Ninject是一款开源的轻量级的依赖注入插件.从接触ioc以来,一直都是使用这个,感觉用起来还是不错的,配置起来也很方便简单.在mvc中更是基本傻瓜式的配置. 开发前的准备 新建一个mvc3项 ...

  5. 整合jQuery和Prototype遇到的问题.

    由于项目要在旧的服务器上面运行,而旧的服务器底层用了Prototype,所以需要解决jQuery和Prototype冲突的问题. 一.$符号冲突问题 这个还是很好解决的. jQuery.noConfl ...

  6. Windows 2008 R2 X64 安装WebsitePanel(WSP虚拟主机管理面板)

                   Windows 2008 R2 X64  安装WebsitePanel(WSP2.0虚拟主机管理面板) 估计很多同学都还不知道WebsitePanel是什么东东吧,Web ...

  7. jquery.pagination +JSON 动态无刷新分页

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SqlPage.aspx.cs& ...

  8. [.ashx檔?泛型处理例程?]基础入门#1....能否用中文教会我?别说火星文?

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_01.aspx [.ashx檔?泛型处理例程? ...

  9. MHA命令系统介绍 --masterha_master_switch

    常用参数介绍 --master_state=dead 强制的参数,参数值为"dead" 或者 "alive" . 如果 设置为 alive 模式,masterh ...

  10. [terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046

      SQL_TRACE/10046 事件是 Oracle 提供的用于进行 SQL 跟踪的手段,在日常的数据库问题诊断和解决中是非常常用的方法.但其生成的trace文件需要tkprof工具生成一个可供人 ...