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

📄 llist.cpp

📁 用VC编写的单链表 是数据结构中线性表中的一种
💻 CPP
字号:
// llist.cpp: implementation of the llist class.
//
//////////////////////////////////////////////////////////////////////

#include "llist.h"
#include "link.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


bool llist::insert(const double& item)
{
	fence->next=new link(item,fence->next);
	if(tail==fence)tail=fence->next;
	rightcnt++;
	return true;
}

bool llist::append(const double &item)
{
	tail=tail->next=new link(item,NULL);
	rightcnt++;
	return true;

}

bool llist::remove(double &it)
{
	if(fence->next==NULL)return false;
	it=fence->next->element;
    link* itemp=fence->next;
	fence->next=itemp->next;
	if(tail==itemp)tail=fence;
	delete itemp;
	rightcnt++;
	return true;

}

void llist::prev()
{
	link *temp=head;
	if(fence==head)return;
	while(temp->next!=fence)temp=temp->next;
	fence=temp;
	leftcnt--;rightcnt++;

}

bool llist::setpos(int pos)
{
	if((pos<0)||(pos>rightcnt+leftcnt))return false;
	fence=head;
	for(int i=0;i<pos;i++)
		fence=fence->next;
	return true;

}

void llist::print() const
{
	link* temp=head;
	cout<<"< ";
	while(temp->next!=NULL)
	{
		cout<<temp->next->element<<" ";
		temp=temp->next;
	}
	cout<<" >\n";
}

bool llist::exchange()
{
    link* first;
	link* mid;
	link* last;
	link* temp;
	int Temp;
	first=NULL;
	last=head->next;
	mid=head;
    while(last!=NULL)
	{
		mid->next=first;
		first=mid;
		mid=last;
		last=last->next;
	}
	mid->next=first;
	temp=head;
	head=tail;
	tail=temp;
    Temp=leftcnt;
	leftcnt=rightcnt;
	rightcnt=Temp;
	temp=new link;
	temp->next=head;
	head=temp;
	setend();
	prev();
    delete fence->next;
	fence->next=NULL;
	tail=fence;

	return true;

}

⌨️ 快捷键说明

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