在线文档教程
C++
容器 | Containers

std::stack

STD:堆栈

Defined in header
template< class T, class Container = std::deque<T> > class stack;

std::stack类是一个容器适配器,它为程序员提供了堆栈的功能--具体来说,是一个filo%281先进,最后输出%29数据结构。

类模板充当底层容器的包装器--只提供一组特定的函数。堆栈从底层容器的后面推入并弹出元素,称为堆栈顶部。

模板参数

T-The type of the stored elements. The behavior is undefined if T is not the same type as Container::value_type. (since C++17)
Container-The type of the underlying container to use to store the elements. The container must satisfy the requirements of SequenceContainer. Additionally, it must provide the following functions with the usual semantics: back() push_back() pop_back() The standard containers std::vector, std::deque and std::list satisfy these requirements.

  • back()

  • push_back()

  • pop_back()

标准容器std::vector,,,std::dequestd::list满足这些要求。

成员类型

Member typeDefinition
container_typeContainer
value_typeContainer::value_type
size_typeContainer::size_type
referenceContainer::reference
const_referenceContainer::const_reference

成员函数

(constructor)constructs the stack (public member function)
(destructor)destructs the stack (public member function)
operator=assigns values to the container adaptor (public member function)

元素存取

顶层访问顶层元素%28公共成员函数%29

容量

空检查基础容器是否为空%28公共成员函数%29

Size返回元素数%28公共成员函数%29

修饰符

推送顶部%28公共成员函数%29的插入元素

将%28C++11%29构造在顶部的元素在顶部%28公共成员函数%29

POP移除顶层元素%28公共成员函数%29

交换交换内容%28公共成员函数%29

成员对象

容器c底层容器%28受保护成员对象%29

非会员职能

operator==operator!=operatoroperator>=lexicographically compares the values in the stack (function template)
std::swap(std::stack)specializes the std::swap algorithm (function template)

帮助者类

std::uses_allocator (C++11)specializes the std::uses_allocator type trait (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/容器/堆栈