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

📄 dcirlist.h

📁 数据结构头文件源代码
💻 H
字号:
#include"DLNode.h"

template<class T>
class DCirList
{
	private:
		DLNode<T> *head;
		int size;
		DLNode<T> *currPtr;
	public:
		T data;
		DCirList(void)
		{
			head=new DLNode<T>();
			head->next=head;
			head->prior=head;
			size=0;
		};
		~DCirList(void);
		{
			ClearList();
			delete head;
		};

		int ListSize(void)const;
		{return size;};
        void EmptyList(void)const;
		{
			if(size<=0) return 1;
			else return 0;
		}
		DLNode<T> *Index(int pos);
		void Insert(const T &item,int pos);
		T Delete(int pos);
		T GetData(int pos);
		void ClearList(void);

		//遍历双循环链表的成员函数
		DLNode<T> *NextReset(int pos=0);
		DLNode<T> *Next(void);
		int NextEndOFList()const;
};

template<class T>
void DCirList::Insert(const T &item,int pos)
{
	DLNode<T> *p=Index(pos);
	DLNode<T> *newNode=new DLNode<T>(item,NULL,NULL);
	newnode->prior=p->prior;
	newnode->next=p;
	p->prior->next=newnode;
	size++;
}
template<class T>
T DCirList::Delete(int pos)
{
	if(size==0)
	{
		cout<<"链表已空无元素可删!"<<endl;
		exit(0);
	}
	DLNode<T> *p=Index(pos);
	p->prior->next=p->next;
	p->next->prior=p->prior;
	T data=p->data;
	delete p;
	size--;
	return data;
}
template<class T>
T DCirList<T>::GetData(int pos)
{
	if(pos<0||pos>size-1)
	{
		cout<<"参数pos越界出错!"<<endl;
		exit(0);
	}

	DLNode<T> *p=Index(pos);
	return p->data;
}
template<class T>
void DCirList<T>::Clearlist(void)
{
	DLNode<T>*p, *pl;
	p=head->next;
	while(p!=head)
	{
		pl=p;
		p=p->next;
		delete pl;
	}
	size=0;
}
template<class T>
DLNode<T>* DCirLIst<T>::NextReset(int pos)
{
	if(head==NULL)return NULL;
	if(pos<-1||pos>=size)
	{
		cout<<"参数出错!"<<endl;
		exit(0);
	}
	if(pos==-1)return head;
	if(pos==0)currPtr=head->next;
	else
	{
		currPtr=head->next;
		DLNode<T>prevPtr=head;
		for(int i=0;i<pos;i++)
		{
			prevPtr=currPtr;
			currPtr=currPtr->next;
		}
	}
	return currPtr;
}
template<class T>
DLNode<T>* DCirList<T>::Next(void)
{
	currPrt=currPtr-next;
	return currPtr;
}
template<class T>
int  DCirList<T>::EndOfList(void)const
//currPrt判断是否指在链表尾是返回1否返回0
{
	if(currPtr==head)return 1;
	else return 0;
}
template<class T>
int DCirList<T>::NextEndOfList(void)
{
	if(currPtr->next==head) return 1;
	else return 0;
}
template<class T>
T DCirList<T>::DeleteAfter()
{
	DLNode<T> *p=currPtr->next;
	currPtr->next=p->next;
	p->next-prior=p->prior;
	T data=p->data;
	delete p;
	size--;
	return data;
}
























⌨️ 快捷键说明

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