STL中栈一共有5个常用操作函数:top()、push()、pop()、 size()、empty()
在STL中,栈是以别的容器作为底部结构,再将接口改变,使之符合栈的特性。如果不指定容器,默认是用deque来作为其底层数据结构的。
#include <stack>
#include <vector>
#include <list>
#include <iostream>
using namespace std;
int main()
{
stack<int> s1;
stack<int,vector<int> > s2;
stack<int,list<int> > s3;
int i=1;
for(i=1;i<10;i++)
{
s1.push(i);
s2.push(i);
s3.push(i);
}
cout <<s1.size()<<endl;
while(!s1.empty())
{
cout<<s1.top()<<" ";
s1.pop();
}
cout<<endl;
cout <<s2.size()<<endl;
while(!s2.empty())
{
cout<<s2.top()<<" ";
s2.pop();
}
cout<<endl;
cout <<s3.size()<<endl;
while(!s3.empty())
{
cout<<s3.top()<<" ";
s3.pop();
}
cout<<endl;
return 0;
}