std(9)stack容器

stack容器是一个先进后出的容器,stack只有顶端的元素才能被外界访问到,不提供遍历也不提供迭代器。

1.构造函数提供两种,一种是新建一个空对象,另一个是使用一个stack的对象来进行构造

std::stack<int> sta;

std::stack<int>(sta) sta1;

2.赋值操作提供“=”赋值

std::stack<int> sta;

std::stack<int> sta1;

sta=sta1;

3.对stack中元素的操作。push向栈顶插入元素,pop从栈顶移除一个函数,top获取栈顶元素的值

std::stack<int> sta;

sta.push(10);

sta.push(20);

sta.push(30);

int a = sta.top();

sta.pop();

4.获取stack对象大小信息。empty判断satack容器是否为空,size返回stack中元素的个数

std::stack<int> sta;

sta.push(10);

sta.push(20);

sta.push(30);

bool isEmpty = sta.empty();

int size = sta.size();

原文地址:https://www.cnblogs.com/maycpou/p/14322535.html