欢迎来到天天文库
浏览记录
ID:47906155
大小:49.53 KB
页数:5页
时间:2019-10-22
《数据结构1-3答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.3//getthelengthofastringIntstrlen(Stringsi);//comparetwostriforsl>s2;,0forsl==s2,andforsl2、fthesubstring//andlenisthelengthofthesubstringStringsubstr(intbeg,intlen,Stringsi);1.4//ListabstractclassTemplateclassList{Public://Reiinitializethelist.Thedientisresponsiblefor//reclaimingthestorageusedbythelistelements.Virtualvoidclear()=0;//Insertanelementatthefrontoftheri3、ghtpartition.//Returntrueifsuccessful,falseifthelistisfull・Virtualboolappend(constElem&)=0;//Removethefirstelementofrightpartition.Return//trueifsuccessful,falseifrightpartitionisempty.//Theelementremovedisreturnedintheparameter.Virtualboolremove(Elem&)=0;//Placefenceatliststart,makingl4、eftpartitionempty.VirtualvoidsetStart()=O;//Placefenceatlistend,makingrightpartitionemptyVirtualvoidsetEnd()=0;//Movefenceonestepleft;nochangeifalreadyatstartVirtualvoidprev()=0;//Movefenceonestepright;nochangeifalreadyatendVirtualvoidnext()=0;//ReturnlengthofleftpartitionVirtualintrigh5、tLength()const=0;//ReturnlengthofrightpartitionVirtualintrightLength()const=O;//Ifposormoreelementsareinthelist,setthesize//ofleftpartitiontoposandreturntrue.Otherwise,//donothingandreturnfalse・VirtualboolsetPos(intpos)=0;//Returninfirstparameterthefirstelementofthe//rightpartition.Retu6、rntrueifsuccessful,false//iftherightpartitionisempty.VirtualboolgetValue(Elem&)const=0;//Printthecontentsofthelist.Virtualvoidprint()const=0;};1.7Analgorithmisamethodoraprocessfollowedtosolveaproblem・Butnoteveryproblemhaveanalgorithm.Becausewhenaprogramisinaninfiniteloop,thisproblemcann7、otbesolved・Beside,someproblemsuchasthehatingproblemarenon-computable.What'smore,someproblemmayhaverftacleardefinition,wecannotknowthesolutionyet.1.8AnalgorithmisarecipeforsolvingaproblemwhosestepsareconCreteandunambiguous.Thatistosaythealgorithmiscorrect,offinitelength‘andtermi
2、fthesubstring//andlenisthelengthofthesubstringStringsubstr(intbeg,intlen,Stringsi);1.4//ListabstractclassTemplateclassList{Public://Reiinitializethelist.Thedientisresponsiblefor//reclaimingthestorageusedbythelistelements.Virtualvoidclear()=0;//Insertanelementatthefrontoftheri
3、ghtpartition.//Returntrueifsuccessful,falseifthelistisfull・Virtualboolappend(constElem&)=0;//Removethefirstelementofrightpartition.Return//trueifsuccessful,falseifrightpartitionisempty.//Theelementremovedisreturnedintheparameter.Virtualboolremove(Elem&)=0;//Placefenceatliststart,makingl
4、eftpartitionempty.VirtualvoidsetStart()=O;//Placefenceatlistend,makingrightpartitionemptyVirtualvoidsetEnd()=0;//Movefenceonestepleft;nochangeifalreadyatstartVirtualvoidprev()=0;//Movefenceonestepright;nochangeifalreadyatendVirtualvoidnext()=0;//ReturnlengthofleftpartitionVirtualintrigh
5、tLength()const=0;//ReturnlengthofrightpartitionVirtualintrightLength()const=O;//Ifposormoreelementsareinthelist,setthesize//ofleftpartitiontoposandreturntrue.Otherwise,//donothingandreturnfalse・VirtualboolsetPos(intpos)=0;//Returninfirstparameterthefirstelementofthe//rightpartition.Retu
6、rntrueifsuccessful,false//iftherightpartitionisempty.VirtualboolgetValue(Elem&)const=0;//Printthecontentsofthelist.Virtualvoidprint()const=0;};1.7Analgorithmisamethodoraprocessfollowedtosolveaproblem・Butnoteveryproblemhaveanalgorithm.Becausewhenaprogramisinaninfiniteloop,thisproblemcann
7、otbesolved・Beside,someproblemsuchasthehatingproblemarenon-computable.What'smore,someproblemmayhaverftacleardefinition,wecannotknowthesolutionyet.1.8AnalgorithmisarecipeforsolvingaproblemwhosestepsareconCreteandunambiguous.Thatistosaythealgorithmiscorrect,offinitelength‘andtermi
此文档下载收益归作者所有