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

📄 4-10.h

📁 数据结构头文件源代码
💻 H
字号:
template<class T> class LinList;

template<class T>
class ListNode
{
	private:
		ListNode<T> *next;
	public:
		T data;

		ListNode(const T &item,ListNode<T> *ptrNext)
		{
			data=item;
			next=ptrNext;
		};
		~ListNode(){};
};

template<class T>
class LinList
{
	private:
		ListNode<T> *head;
		int size;
    public:
		LinList(void)
		{
			head=Null;
			size=0;
		}
		~LinList(void)
		{
			ClearList();
			head=NULL;
		}
		void Insert(const T &item,int pos);
		T    Delete(int pos);
		void ClearList();
};
template <class T>
void LinList<T>::Insert(const T &item,int pos)
{
	if(pos==0)
	{	
		ListNode<T> *p=Index(pos);
	    ListNode<T> *newNode=new ListNode<T>(item,p);
		head=newNode;
	}
	else
	{
		ListNode<T> *p=Index(pos-1);
	    ListNode<T> *newNode=new ListNode<T>(item,p->next);
	    p->next=newNode;
	}
	size++;
}
T LinList<T>::Delete(int pos)
{
	if(pos==0)
	{
		ListNode<T> *p=Index(pos);
		head=p->next;
	}
	else
	{ 
		ListNode<T> *p=Index(pos-1);
		p->next=p->next->next;
	}
	size--;
}
template<class T>
void LinList::ClearList(void)
{
	ListNode<T> *p,*pl;
	p=head;
	while(p!=NULL)
	{
		pl=p;
		p=p->next;
		delete pl;
	}
	szie=0;
}

⌨️ 快捷键说明

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