资源描述:
《数据结构与算法分析 第12章 答案 larry nyhoff 清华大学出版社》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter12Chapter12:Searching:BinaryTreesandHashTablesExercises12.11.4,62.4,1,2,33.4,6,54.4,1,05.4,6,7,86.templatevoidlinearSearch(ElementTypex[],ElementTypeitem,intcapacity,intn,bool&found,int&loc)/*---------------------------------------------------------
2、---------------Linearsearchaliststoredinanarrayxforanitem,whichisaddedattheendofthelist,toimproveperformance.Precondition:nisthenumberofitemsinthearrayandislessthanthearray'scapacity.Postcondition:foundistrueandlocisthepositionofitemifthesearchissuccessful;otherwisefoundisfals
3、eandloc==n.------------------------------------------------------------------------*/{assert(nvoidlinearSearch(ElementTypex[],ElementTypeitem,intn,bool&found,int&loc)/*-----------
4、-------------------------------------------------------------Linearsearchanorderedliststoredinanarrayxforanitem.Precondition:nisthenumberofitemsstoredinthearray.Postcondition:foundistrueandlocisthepositionofitemifthesearchissuccessful;otherwisefoundisfalse.--------------------
5、----------------------------------------------------*/{loc=0;while(locx[loc])loc++;found=(locvoidrecLinearSearch(ElementTypex[],ElementTypeitem,intn,intstart,bool&found,int&loc)/*-------------------------
6、-----------------------------------------------Recursivelylinearsearchaliststoredinanarrayxforanitem.Precondition:nisthenumberofitemsinthearrayand0<=start<=n.Initialcalliswithstart=0.Postcondition:foundistrueandlocisthepositionofitemifthesearchissuccessful;otherwisefoundisfals
7、eandloc==n.------------------------------------------------------------------------*/{loc=start;if(start==n)found=false;elseif(item==x[start])found=true;elserecLinearSearch(x,item,n,start+1,found,loc);}9.templatevoidmoveFrontLinearSearch(Node*
8、first,ElementTypeitem,bool&found,Node*locptr);/*