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

📄 list.h

📁 简单的队列的实现
💻 H
字号:
#include <iostream.h>
#include "node.h"
class linklist
{
private:
	node* head;
	node* pcurrent;
public:
	linklist();
	node* haddr();
	node* pcaddr();
	void insertbefore(const int& item);
	void insertafter(const int& item);
	void del();
	void result();
};
linklist::linklist()
{
	//
	head=new node(-1,NULL);
	pcurrent=head;
}
void linklist::insertbefore(const int& item)
{
	node* p=head;
	node* s;
	if(head->next==NULL)
	{
		node* p=new node(item,NULL);
		head->next=p;
		pcurrent=p;
	}
	else
	{
		while(p->next!=pcurrent)
			p=p->next;
		s=new node(item,pcurrent);
		p->next=s;
		pcurrent=s;
	}
}
void linklist::insertafter(const int& item)
{
	node*p=new node(item,pcurrent->next);
	pcurrent->next=p;
	pcurrent=p;
}
void linklist::del()
{
	if(head->next==NULL)
		cout<<"no element left"<<endl;
	else
	{
		node*p=head;
		while(p->next!=pcurrent)
			p=p->next;
		p->next=pcurrent->next;
		delete pcurrent;
		pcurrent=p->next;
	}
}
node* linklist::haddr()
{
	return head;
}
node* linklist::pcaddr()
{
	return pcurrent;
}
void linklist::result()
{
	node* p=head->next;
	while(p!=NULL)
	{
		cout<<p->data<<"\n";
		p=p->next;
	}
}

⌨️ 快捷键说明

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