Template Stack

#include
#include
using namespace std;
template 
class Stack
{
public:
	Stack()
	{
		top = -1;
	}//初始化栈
	void push(const T1 &item)
	{
		assert(!isfull());
		++top;
		list[top] = item;
	}//将item压入栈
	T1 pop()
	{
		assert(!isempty());
		top--;
		return list[top];
		
	}//出栈
	void clear()
	{
		top = -1;
	}//清空栈
	const T1 &peek() const
	{
		int temp = list[top];
		return list[top];
	}//访问栈顶元素
	bool isfull() const
	{
		return top == Size-1 ? true : false;
	}//判断栈满
	bool isempty() const
	{
		return top  == -1 ? true : false;
	}//判断栈空
	void print()
	{
		for(int i = top;i>=0;i--)
		{
			cout< a;
	Stack b;
	a.push(1);
	a.push(2);
	a.push(3);
	a.push(4);
	a.push(5);
	a.print();
	cout< S;
	S.push(2);
	S.push(3);
	S.push(4);
	S.print();//输出4 3 2
	cout<

你可能感兴趣的:(Template Stack)