一、stack基本概念
stack是一种先进后出的数据结构,它只有一个出口,栈中只有顶端的元素才可以被外界使用,因此栈不允许有遍历行为。
栈中进入数据称为:入栈push
栈中弹出数据称为:出栈pop
二、stack常用接口
stack<int> s; //创建栈容器
s.push(10); //向栈里边添加元素
s.empty() //判断栈内是否为空
s.top() //栈顶元素
s.pop(); //弹出栈顶元素
void text01()
{
stack<int> s;
s.push(10);
s.push(20);
s.push(30);
while(!s.empty())
{
cout << "栈顶元素:" << s.top() << endl;
s.pop();
}
cout << "栈的大小:" << s.size() << endl;
}