list.h

来自「简单的队列的实现」· C头文件 代码 · 共 79 行

H
79
字号
#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 + =
减小字号Ctrl + -
显示快捷键?