欢迎来到天天文库
浏览记录
ID:35342699
大小:64.65 KB
页数:12页
时间:2019-03-23
《数据结构-带头结点的循环链表》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、FilechainNode・h#ifndefchainNode_#definechainNode_templatestruetchainNode{//datamembersTelement;chainNode*next;//methodschainNode(){next=NULL;}chainNode(constT&element){this->element=element;this->next=NULL;}chainNode(constT&element,chainNode*next){this->element=
2、element;this->next=next;}};#endifFilelinnerList・h//abstractclasslinearList//abstractdatatypespecificationforlinearlistdatastructure//allmethodsarepurevirtualfunctions#ifndeflinearList_#definelinearList_#ineludeusingnamespacestd;templateclasslinearListpublic:
3、virtual~linearList(){};virtualboolemptyf)const=0;//returntrueifflistisemptyvirtualintsize()const=0;//returnnumberofelementsinlistvirtualT&get(intthelndex)const=0;//returnelementwhoseindexisthelndexvirtualintindexOffconstT&theElement)const=0;//returnindexoffirstoccureneeoftheE
4、lementvirtualvoiderase(intthelndex)=0;//removetheelementwhoseindexisthelndexvirtualvoidinsertfintthelndex,constT&theElement)=0;//inserttheElementsothatitsindexisthelndexvirtualvoidoutput(ostream&out)const=0;//insertlistintostreamout};#endifFilecircularListWithHeader・h//circul
5、arListlistwithheadernodeanditerator#ifndefcircularListWithHeader_#definecircularListWithHeader_#include#include#include#includeHchainNode・hH#includeHmyExceptions.hH#includeHlinearList・h”usingnamespacestd;templatevclassT〉classcircularListWithHeader{p
6、ublic://构造函数circularListWithHeader();//somemethodsboolempty(){returnlistSize=0;}intsize()const{returnlistSize;}T&get(intthelndex)const;intindexOf(constT&theElement)const;voiderase(intthelndex);voidinsert(intthelndex,constT&theElement);voidoutput(ostream&out)const;voidreverse(
7、);//iteratorstostartandendoflistclassiterator;iteratorbegin(){returniterator(headerNode->next);}iteratorend(){returniterator(headerNode);}//iteratorforchainclassiterator{public://typedefsrequiredbyC++foraforwarditeratortypedefforward_iterator_tagiterator_category;typedefTvalu
8、e_type;typedefptrdiff_tdifference_type;typedefT*pointer;typedefTeren
此文档下载收益归作者所有