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

📄 lxlist.cpp

📁 vc编写的数据结构
💻 CPP
字号:
// lxlist.cpp: implementation of the lxlist class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "lxlist.h"

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

lxlist::lxlist(int size=defaultlistsize)
{
	init();
}

lxlist::~lxlist()
{
	removeall();
}

void lxlist::clear()
{
    removeall(); 
	init();
}

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

bool lxlist::append(const lxedge &item)
{
	tail=tail->next=new lxllink (item,NULL);
	rightcnt++;
    return true;
}

bool lxlist::remove(lxedge &it)
{
	if(fence->next==NULL) return false;
	it=fence->next->element;
	lxllink * ltemp=fence->next;
	fence->next=ltemp->next;
	if(tail==ltemp) tail=fence;
	delete ltemp;
	rightcnt--;
	return true;
}

void lxlist::setStart()
{
	fence=head; rightcnt+=leftcnt; leftcnt=0;
}

void lxlist::setEnd()
{
	fence=tail; leftcnt+=rightcnt; rightcnt=0;
}

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

void lxlist::next()
{
	if(fence!=tail)
	{ fence=fence->next;rightcnt--;leftcnt++; }
}

int lxlist::leftLength() const
{
	return leftcnt;
}

int lxlist::rightLength() const
{
	return rightcnt;
}

bool lxlist::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;
}

bool lxlist::getValue(lxedge &it) const
{
	if(rightLength()==0) return false;
	it=fence->next->element;
	return true;
}

void lxlist::print() const
{
/*	Link * temp=head;
	cout<<"< ";
	while(temp!=fence) {
		cout<<temp->next->element<<" ";
		temp=temp->next;
	}
	cout<<"| ";
	while(temp->next!=NULL) {
		cout<<temp->next->element<<" ";
		temp=temp->next;
	}
	cout<<">\n";
	*/
}


void lxlist::init()
{
	fence = tail = head = new lxllink(NULL);
	leftcnt=rightcnt=0;
}

void lxlist::removeall()
{
	while(head!=NULL){
		fence=head;
		head=head->next;
		delete fence;
	}
}

⌨️ 快捷键说明

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