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

📄 lianbiao.h

📁 本程序中分别用数组和链表实现了环形队列
💻 H
字号:
#include<iostream.h>

//template<class T>
class  Node{
public:
	int info;
	Node *next;
	Node *pre;
	Node(int el, Node *ptr=0, Node *p=0)
	{ 
		info=el; 
		next=ptr;
		pre=p;
	}
};

//template<class T>
class  List{
public:
	List(){ tail=0; }
	~List();
	int isEmpty() { return tail==0;}
	void deleteHead();
	void addtoTail(int);
	void print();
	void enter();
private:
	Node *tail;
};
//template<class T>
List::~List()
{
	for(Node* p, *q; !isEmpty(); )
	{
		p=tail->next;
		q=p->next;

		q->pre=tail;
		tail->next=q;
		delete p;	
	}
}

//template<class T>
void List::addtoTail(int el)
{
	if(isEmpty())
	{
		tail->next=new Node(el);
		tail->pre= tail->next=tail;
	}
	else
	{
		Node *head=tail->next;
		tail->next=new Node(el,head,tail);
		tail=tail->next;
		head->pre=tail;		
	}
}
//template<class T>
void List::deleteHead()
{
	if(isEmpty())
	{
		cout<<"Empty queue!"<<endl;
	}
	else
	{
		Node *head=tail->next;
		tail->next=head->next;
		head->next->pre=tail;
		delete head;
	}
}
//template<class T>
void List::print()
{
	Node* p;
	cout<<"Queue is:"<<endl;
	for(p=tail->next; p!=0; p=p->next )
	{
		cout<< p->info;
		if(p->next!=tail)cout<<" -> ";
	}
	cout<<endl;
}
//template<class T>
void List::enter()
{
	cout<<"请依次输入队列的元素: \n";
	int temp;
	while(cin>>temp ){
		addtoTail(temp);
	}
	cin.clear();
}

⌨️ 快捷键说明

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