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

📄 binary_search_singlelist.h

📁 数据结构-二叉树
💻 H
字号:
#include<iostream.h>

template<class type> class SetList;
template<class type> class SetNode
{
	friend class SetList<type>;
	public:
		SetNode(const type& item):data(item),link(NULL){};
	private:
		type data;
		char name,six,age;
		SetNode<type> * link;
};

template<class type> class SetList
{
	public:
		SetList();
		void MakeEmpty();
		int AddMember(const type& x);
		int DelMember(const type& x);
		int Contains(const type& x);
		Display();
		~SetList();
		//type &Min();
		//type &Max();
	private:
		SetNode<type> * first, * last;		
};

template<class type>SetList<type>::SetList()
{
	first=last=new SetNode<type>(0);
}

template<class type> int SetList<type>::Contains(const type & x)
{
	SetNode<type> * temp=first->link;
	while(temp!=NULL&&temp->data<x)
		temp=temp->link;
	if(temp!=NULL&&temp->data==x)
		return 1;
	else
		return 0;
}

template<class type> int SetList<type>::AddMember(const type& x)
{
	SetNode<type> * p=first->link,* q=first;
	while(p!=NULL&&p->data<x)
	{
		q=p;
		p=p->link;
	}
	if(p!=NULL&&p->data==x)
		return 0;
	SetNode<type> * s=new SetNode<type>(x);
	s->link=p;
	q->link=s;
	return 1;
}

template <class type> int SetList<type>::DelMember(const type& x)
{
	SetNode<type> * p=first->link, * q=first;
	while(p!=NULL&&p->data<x)
	{
		q=p;
		p=p->link;
	}
	if(p!=NULL&&p->data==x)
	{
		q->link=p->link;
		if(p==last)
			last=q;
		delete p;
		return 1;
	}
	else
		return 0;
}

template<class type> void SetList<type>::MakeEmpty()
{
	SetNode<type> * del;	
	while(first->link!=NULL)
	{    del=first->link;
	     first->link=first->link->link;
		 delete del;
	};
	last->link=first->link;
	last=first;
	cout<<"成功清空链表!";
}

template<class type> SetList<type>::~SetList()
{
	SetNode<type> * del;
	while(first!=0)
	{    del=first;
	     first=first->link;
		 delete del;
	};
	
	cout<<"成功释放链表空间!"<<'\n';
}


template<class type> SetList<type>::Display()
{
	SetNode<type> * print;
	print=first->link;
	if(print==NULL)
		cout<<endl<<"链表为空!";
	else
	{		
		cout<<endl<<"当前链表中所有结点 : ";
		while(print!=NULL)
		{   
			cout<<"->"<<print->data;         
			print=print->link;
		}
	}
}

⌨️ 快捷键说明

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