首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::stack

Defined in header <stack>

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 type

Definition

container_type

Container

value_type

Container::value_type

size_type

Container::size_type

reference

Container::reference

const_reference

Container::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!=operator<operator<=operator>operator>=

lexicographically compares the values in the stack (function template)

std::swap(std::stack)

specializes the std::swap algorithm (function template)

帮助者类

std::uses_allocator<std::stack> (C++11)

specializes the std::uses_allocator type trait (function template)

代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券