#include<iostream>
#include<stack>
using namespace std;
int main()
{
stack<double> stac;
for (double i = 0; i < 10.0; i++)
{
stac.push(i);
}
while (!stac.empty())
{
cout << stac.top() << endl;
stac.pop();
}
cout << "栈的大小为" << stac.size() << endl;
system("pause");
return 0;
}
主要的5个函数的调用
- push
- pop
- top
- size
- empty
- C++中stack 是容器么?
是容器,需要调用头文件#include<stack> - 我们使用的stack是属于那个版本的STL?
C++11 - 我们使用的STL中stack是如何实现的?
stack是默认使用deque(双头队列)来实现的 - stack 提供迭代器来遍历stack空间么?
因为栈和队列不支持迭代器,不能对任意元素进行访问