#include<vector>
#include<list>
namespace Ljw
{ //给个缺省值
template<class T,class Container=vector<int>>//Container,vector和list的随意切换
class stack
{
public:
void push(const T& x)
{
_con.push_back(x);
}
T& top()
{
return _con.back();
}
void pop()
{
_con.pop_back();
}
void size()
{
return _con.size();
}
bool empty()
{
return _con.empty();
}
private:
Container _con;
};
void test1()
{
stack<int,vector<int>> st;//vector和list的随意切换
st.push(1);
st.push(2);
st.push(3);
st.pop();
cout << st.top() << endl;
stack<int, list<int>>st1; st.push(1);
st.push(2);
st.push(3);
st.pop();
cout << st.top() << endl;
}
}
07-24
878
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)