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

📄 tlist.h

📁 迷宫问题
💻 H
字号:

#ifndef TLIST_H
#define TLIST_H

template<class T>
class TNode
{
public:
	TNode (const T& el, TNode<T> *ptr=0):	info(el), next(ptr){}
	T info;
	TNode<T> *next;
	
};

template<class T>
class TLIST
{
public:
	TLIST()
	{
		head=tail=0;
	}
	~TLIST();
	bool isempty();
	void push_back(const T& el);
	T pop_back();
	const T& getLast() const;
private:
	TNode<T> *head, *tail;
};

template<class T>
bool TLIST<T>::isempty()
{
	return head==0;
}

template<class T>
TLIST<T>::~TLIST()
{
	for(TNode<T> *p;!isempty();)
	{
		p=head->next;
		delete head;
		head=p;
	}
}

template<class T>
void TLIST<T>::push_back(const T& el)
{
	if(tail!=0)
	{
		tail->next=new TNode<T>(el);
		tail=tail->next;
	}else
		head=tail=new TNode<T>(el);
}
template<class T>
T TLIST<T>:: pop_back()
{
	T el=tail->info;
	if(head==tail)
	{
		delete head;
		head = tail =0;
	}
	else
	{
		TNode<T> *tmp;
		for(tmp=head; tmp->next!=tail; tmp=tmp->next);
		delete tail;
		tail=tmp;
		tail->next=0;
	}
	return el;
}
template<class T>
const T& TLIST<T>::getLast() const
{
	return tail->info;
}


#endif

⌨️ 快捷键说明

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