?? ll.cpp
字號:
// LL.cpp: implementation of the LL class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LL.h"
#ifndef NULL
#define NULL 0
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LL::LL()
{
head=&headdum;
tail=&taildum;
head->next=tail;
head->prev=NULL;
tail->prev=head;
tail->next=NULL;
length=0;
cur=head;
}
LL::~LL()
{
}
void LL::addhead(node *nd)
{
length++;
nd->next=head->next;
head->next=nd;
nd->prev=head;
nd->next->prev=nd;
}
void LL::addtail(node *nd)
{
length++;
nd->next=tail;
nd->prev=tail->prev;
tail->prev->next=nd;
tail->prev=nd;
}
node *LL::delhead()
{
node *temp;
temp=head->next;
head->next=temp->next;
temp->next->prev=head;
length--;
return temp;
}
node *LL::deltail()
{
node *temp;
temp=tail->prev;
temp->prev->next=tail;
tail->prev=temp->prev;
length--;
return temp;
}
node *LL::getindex(int index)
{
int i;
node *temp;
if((length/2)>=index)
{
i=0;
temp=head->next;
while(temp!=tail&&i<index)
{ temp=temp->next; i++;}
if(temp==tail)
return NULL;
else
return temp;
}
else
{
temp=tail->prev;
i=length-1;
while(temp!=head&&i>index)
{temp=temp->prev; i--;}
if(temp==head)
return NULL;
else
return temp;
}
}
bool LL::find(node *nd)
{
node *temp;
temp=head->next;
while(temp!=tail&&temp!=nd)
temp=temp->next;
if(temp==tail)
return false;
else
return true;
}
int LL::getlength()
{
return length;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -