template<class T> class DouListNode<br />{<br /> T data;<br /> DouListNode<T>* link;<br /> DouListNode<T>* prior;<br /> public:<br /> DouListNode():link(NULL),prior(NULL){}<br /> DouListNode(T value):link(NULL),prior(NULL),data(value){}<br /> ~DouListNode(){};<br /> void SetLink(DouListNode<T>* next);<br /> void SetPrior(DouListNode<T>* pre);<br /> DouListNode<T>* GetLink();<br /> DouListNode<T>* GetPrior();<br /> T& GetData();<br />};<br />template<class T><br />void DouListNode<T>::SetLink(DouListNode<T>* next)<br />{<br /> link=next;<br />}<br />template<class T><br />void DouListNode<T>::SetPrior(DouListNode<T>* pre)<br />{<br /> prior=pre;<br />}<br />template<class T><br />DouListNode<T>* DouListNode<T>::GetLink()<br />{<br /> return link;<br />}<br />template<class T><br />DouListNode<T>* DouListNode<T>::GetPrior()<br />{<br /> return prior;<br />}<br />template<class T><br />T& DouListNode<T>::GetData()<br />{<br /> return data;<br />} </p><p>template<class T> class DouList<br />{<br /> DouListNode<T>* head;<br /> DouListNode<T>* tail;<br /> DouListNode<T>* cur;<br /> public:<br /> DouList();<br /> ~DouList(){};<br /> bool AddTail(T value);<br /> bool AddHead(T value);<br /> void RemoveThis(bool direction);<br /> void RemoveAll();<br /> void SetBegin();<br /> int GetCount();<br /> void TowardCur();<br /> void BackCur();<br /> DouListNode<T>* GetCur();<br /> DouListNode<T>* GetHead();<br /> DouListNode<T>* GetTail();<br /> void InsertAfter(T value);<br /> bool IsEmpty();<br /> T GetNext();<br /> T GetPrior();<br />};<br />template<class T><br />DouList<T>::DouList()<br />{<br /> head=tail=new DouListNode<T>;<br /> cur=NULL;<br /> head->SetLink(head);<br /> head->SetPrior(tail);<br />}<br />template<class T><br />bool DouList<T>::AddTail(T value)<br />{<br /> DouListNode<T>* add=new DouListNode<T>(value);<br /> tail->SetLink(add);<br /> add->SetPrior(tail);<br /> tail=tail->GetLink();<br /> tail->SetLink(head);<br /> head->SetPrior(add);<br /> if(tail!=NULL)<br /> {<br /> return true;<br /> }<br /> else<br /> return false;<br />}<br />template<class T><br />bool DouList<T>::AddHead(T value)<br />{<br />DouListNode<T>* add=new DouListNode<T>(value);<br />add->SetPrior(head);<br />add->SetLink(head->GetLink());<br />head->GetLink()->SetPrior(add);<br />head->SetLink(add);<br />if(tail==head)<br />{<br />tail=head->GetLink();<br />}<br />if(add!=NULL)<br />{<br />return true;<br />}<br />else<br />return false;<br />}<br />template<class T><br />void DouList<T>::RemoveThis(bool direction)<br />{<br />if(cur==head)<br />{<br />if(direction==0)<br />cur=cur->GetLink();<br />if(direction==1)<br />cur=cur->GetPrior();<br />}<br />DouListNode<T>* preCur=NULL;<br />DouListNode<T>* nextCur=NULL;<br />preCur=cur->GetPrior();<br />nextCur=cur->GetLink();<br />preCur->SetLink(cur->GetLink());<br />nextCur->SetPrior(cur->GetPrior());<br />if(direction==0)<br />cur=nextCur;<br />if(direction==1)<br />cur=preCur;</p><p>}<br />template<class T><br />void DouList<T>::RemoveAll()<br />{<br />SetBegin();<br />int length=GetCount();<br />for(int i=0;i<length;i++)<br />{<br />RemoveThis(0);<br />}<br />cur=head;<br />}<br />template<class T><br />void DouList<T>::SetBegin()<br />{<br />cur=head;<br />}<br />template<class T><br />int DouList<T>::GetCount()<br />{<br />int num=0;<br />DouListNode<T>* here=cur;<br />while(cur->GetLink()!=here)<br />{<br />cur=cur->GetLink();<br />++num;<br />}<br />cur=cur->GetLink();<br />return num;<br />}<br />template<class T><br />void DouList<T>::TowardCur()<br />{<br />cur=cur->GetLink();<br />}<br />template<class T><br />void DouList<T>::BackCur()<br />{<br />cur=cur->GetPrior();<br />}<br />template<class T><br />DouListNode<T>* DouList<T>::GetCur()<br />{<br />return cur;<br />}<br />template<class T><br />DouListNode<T>* DouList<T>::GetHead()<br />{<br />return head;<br />}<br />template<class T><br />DouListNode<T>* DouList<T>::GetTail()<br />{<br />return tai;<br />}<br />template<class T><br />bool DouList<T>::IsEmpty()<br />{<br />return head->GetLink()==head;<br />}<br />template<class T><br />void DouList<T>::InsertAfter(T value)<br />{<br />DouListNode<T>* add=new DouListNode<T>(value);<br />DouListNode<T>* nextCur=cur->GetLink();<br />cur->SetLink(add);<br />add->SetLink(nextCur);<br />nextCur->SetPrior(add);<br />add->SetPrior(cur);<br />if(cur==tail)<br />{<br />tail=cur->GetLink();<br />}<br />}<br />template<class T><br />T DouList<T>::GetNext()<br />{<br />if(cur==head)<br />cur=cur->GetLink();<br />T num=cur->GetData();<br />cur=cur->GetLink();<br />return num;<br />}<br />template<class T><br />T DouList<T>::GetPrior()<br />{<br />if(cur==head)<br />cur=cur->GetPrior();<br />T num=cur->GetData();<br />cur=cur->GetPrior();<br />return num;<br />}<br />