📄 linklist.h
字号:
/////////////////////////////////////////////////////////////
//* *
// US - RadioSoft:
//
// X-Projects:US_TL(United Starction_Template Languange);
//
// Double Direct LinkList:
//
// __Descriptions:_________________________________
// | |
// |The Link Surpport All Kinds Of Type Data |
// |Elements,It Used The Template Technology |
// | |
// |The Version Can Not Be Released Even If It Is A |
// |Test Version,All Rights Reserved |
// |________________________________________________|
//
// Author: Joe Radlorama
//
// Create Date:20:55 9/20 2007 SuZhou
//* *
/////////////////////////////////////////////////////////////
/////////////////////////////////////
//Define Of The Interface (Node)
/////////////////////////////////////
template<class V>
class Node
{
public:
Node(V v)
{
this->value = v;
};
public:
V value;
Node* next;
Node* prev;
};
/////////////////////////////////////
//Define Of The Interface (Node)
/////////////////////////////////////
template<class E>
class LinkList
{
public:///////////////Constructs/////////////////////
LinkList()
{
this->Length = 0;
Head = new Node<E>(-198459);
Head->next = NULL;
Head->prev = NULL;
_CcurPtr = Head;
}
LinkList(E e)
{
this->Length = -1;
Head = new Node<E>(e);
Head->next = NULL;
Head->prev = NULL;
_CcurPtr = Head;
};
//////////////////////////////////////////////////
private:///////Pointers & Properties//////////////
Node<E>* Head; //The pointer which point to the head of the LinkList
Node<E>* _CcurPtr; //The pointer which point to the current position of the LinkList
Node<E>* _TmpOperator;//This pointer is used in the condition of access the elements in LinkList
int Length;//Current Length Of The LinkList
public://Add To LinkList:
void AddElemt_FR(E e);
void AddElemt_FH(E e);
//////////////////////////////////
public://Remove Operator:
void Remove_FR();
void Remove_FH();
void Remove_Idx(int index);
void Remove_FH_ByObj(E e);
void Remove_FR_ByObj(E e);
void Revove_All(E e);
void Clear();
/////////////////////////////////
public://GetElement By Index:
E operator[] (int index);
/////////////////////////////////
private:
Node<E>* __getThe (int index);
public:
int getLength(void) const;
};
//////////////////////////////////////////
//Implements Of The LinkList
/////////////////////////////////////////
template<class E>
void LinkList<E>::AddElemt_FR(E e)
{
Node<E>* node = new Node<E>(e);
Node<E>* tmpPtr = _CcurPtr;
_CcurPtr->next = node;
//tmpPtr = node;
_CcurPtr = _CcurPtr->next;
_CcurPtr->next = NULL;
_CcurPtr->prev = tmpPtr;
Length++;
};
template<class E>
int LinkList<E>::getLength(void) const
{
return Length;
};
template<class E>
Node<E>* LinkList<E>::__getThe(int index)
{
int i = 0;
_TmpOperator = Head;
while(_TmpOperator)
{
_TmpOperator = _TmpOperator->next;
if(i == index)
{
return _TmpOperator;
}
i++;
}
return NULL;
};
template<class E>
E LinkList<E>::operator[](int index)
{
Node<E> * tmp = this->__getThe(index);
return tmp->value;
};
template<class E>
void LinkList<E>::Remove_FH()
{
Node<E> *tmp = Head->next;
Head->next = Head->next->next;
delete tmp;
Length--;
};
template<class E>
void LinkList<E>::Remove_FR()
{
Node<E> *tmp = _CcurPtr;
_CcurPtr = _CcurPtr->prev;
_CcurPtr->next = NULL;
delete tmp;
Length--;
};
template<class E>
void LinkList<E>::Remove_Idx(int index)
{
Node<E> *tmp = this->__getThe(index-1);
Node<E> *del = tmp->next;
tmp->next = tmp->next->next;
delete del;
}
template<class E>
void LinkList<E>::Clear()
{
int i=0;
Node<E> *tmp = NULL;
while(_CcurPtr!=Head)
{
i++;
tmp = _CcurPtr;
_CcurPtr = _CcurPtr->prev;
//delete tmp;
// printf("%d",i);
}
Length = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -