?? lxlist.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 + -