⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack_singlelist.h

📁 数据结构-递归实验
💻 H
字号:
#include<iostream.h>
#include<assert.h>

template<class type> class Stack;
template<class type> class StackNode
{   
	friend class Stack<type>;
	public:
       // StackNode();
		StackNode(const type&);
	private:
		type data;
		StackNode<type> * next;
};

template<class type> class Stack
{
	public:
		Stack();		
		~Stack();
		void Push(const type&);
		type Pop();
		type GetTop();
		void MakeEmpty();
		int IsEmpty();			
	private:		
		StackNode<type> * first;		
};

/*template<class type> class StackNode<type>::StackNode()
{
	data=0;
	next=NULL;
}*/

template<class type> StackNode<type>::StackNode(const type& value)
{
	data=value;
	next=NULL;
}

template<class type> Stack<type>::Stack()
{
	first=NULL;
}

template<class type> void Stack<type>::Push(const type& item)
{
	StackNode<type> * newnode=new StackNode<type>(item);
	newnode->next=first;
	first=newnode;
	
}

template<class type> type Stack<type>::Pop()
{
	assert(!IsEmpty());
	type retvalue=first->data;
	StackNode<type> * del=first;   
	first=first->next;
	delete del;
	return retvalue;
}

template<class type> type Stack<type>::GetTop()
{
	assert(!IsEmpty());
	return first->data;
}

template<class type> void Stack<type>::MakeEmpty()
{
	
		StackNode<type> * del;
		while(!IsEmpty())
		{
			del=first;
			first=first->next;
			delete del;
		}
		first=NULL;

}

template<class type> int Stack<type>::IsEmpty()
{
	return first==NULL;
}

template <class type> Stack<type>::~Stack()
{
	
		StackNode<type> * del;
		while(first!=NULL)
		{
			del=first;
			first=first->next;
			delete del;
		}
		first=NULL;
	

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -