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

📄 list.cpp

📁 一个类定义的链队列和链表
💻 CPP
字号:
// list.cpp: implementation of the list class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "list.h"
#include "stdlib.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

list::list()
{
	LNode *s = new LNode ();
	s->data=0;
	s->next=NULL;
	list_h=s;

}

list::~list()
{
	Linklist p;
	p=list_h->next;
	while(list_h)
	{
		p=list_h;
		list_h=list_h->next;
		delete p;
	}

}

void list::head_insert(int a)
{
	LNode *s = new LNode();
	s->data=a;
	s->next=list_h->next;
	list_h->next=s;
}

void list::tail_insert(int a)
{
	LNode *s=new LNode();
	s->data=a;

	Linklist p,t;
	t=list_h;
	p=list_h->next;
	while(p!=NULL)
	{
		t=p;
		p=p->next; 
	}
	s->next=p;
	t->next=s;
}

void list::output_list()
{
	Linklist h=list_h->next;
	while(h!=NULL)
	{
		cout<<h->data<<"  ";
		h=h->next;
	}
	cout<<"\n";
}

int list::get_head()
{
	return list_h->next->data;
}

void list::delete_head()
{
	Linklist p=list_h->next;
	if(p==NULL)  exit;
	list_h->next=p->next;
	delete p;
}

void list::delete_tail()
{
	Linklist t,p;
	p=list_h->next;
	t=list_h;
	while(p->next!=NULL)
	{
		t = p;
		p=p->next; 
	}
	t->next=NULL;
	delete p;
}

⌨️ 快捷键说明

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