64,685
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#include <list>
template<typename T, class C = std::list<T>>
class Stack{
public:
typedef typename C::iterator iterator;
iterator begin(){return cc.begin();}
iterator end() {return cc.end();}
void push(const T& vaule){ cc.push_front(vaule); }
void pop(){cc.pop_front();}
T top(){return cc.front(); }
private:
C cc;
};
int _tmain(int argc, _TCHAR* argv[])
{
Stack<int > FF;
FF.push(9);
FF.push(10);
FF.push(11);
Stack<int>::iterator itor= FF.begin();
while (itor != FF.end())
{
std::cout
<<*itor++<<std::endl;
}
std::cout
<<FF.top()<<std::endl;
FF.pop();
std::cout
<<FF.top()<<std::endl;
FF.pop();
std::cout
<<FF.top()<<std::endl;
FF.pop();
return 0;
}
11
10
9
11
10
9
请按任意键继续. . .