欢迎来到天天文库
浏览记录
ID:26120526
大小:166.00 KB
页数:43页
时间:2018-11-24
《数据结构与算法分析 第10章 答案 larry nyhoff 清华大学出版社》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter10Chapter10:ADTImplementations:Recursion,AlgorithmAnalysis,andStandardAlgorithmsProgrammingProblemsSection10.11./*-------------------------------------------------------------------Driverprogramtotestrecursivedigit-countingfunctionofExercise21.Input:NonnegativeintegersOutpu
2、t:Numberofdigitsineachinteger-------------------------------------------------------------------*/#includeusingnamespacestd;intnumDigits(unsignedn);/*-------------------------------------------------------------------Recursivelycountthedigitsinanonnegativeinteger--Exer.2
3、1.Precondition:n>=0Postcondition:Numberofdigitsinnisreturned.-------------------------------------------------------------------*/intmain(){intn;for(;;){cout<<"Enteranonnegativeinteger(-1tostop):";cin>>n;if(n<0)break;cout<<"#digits="<4、()intnumDigits(unsignedn){if(n<10)return1;elsereturn1+numDigits(n/10);}2.Justreplacethefunctiondefinitionin1withthatinExercise22.–229–Chapter103./*-------------------------------------------------------------------Driverprogramtotestreverse-printfunctionofExercise23.Input:Nonnegat5、iveintegersOutput:Thereversalofeachinteger.-------------------------------------------------------------------*/#includeusingnamespacestd;voidprintReverse(unsignedn);/*-------------------------------------------------------------------Recursivelydisplaythedigitsofanonneg6、ativeintegerinreverseorder--Exer.23.Precondition:n>=0Postcondition:Reversalofnhasbeenoutputtocout.-------------------------------------------------------------------*/intmain(){intn;for(;;){cout<<"Enteranonnegativeinteger(-1tostop):";cin>>n;if(n<0)break;cout<<"Reversalis:";print7、Reverse(n);}}//--DefinitionofprintReverse()voidprintReverse(unsignedn){if(n<10)cout<8、ogramtotestpowerfunctionofExercis
4、()intnumDigits(unsignedn){if(n<10)return1;elsereturn1+numDigits(n/10);}2.Justreplacethefunctiondefinitionin1withthatinExercise22.–229–Chapter103./*-------------------------------------------------------------------Driverprogramtotestreverse-printfunctionofExercise23.Input:Nonnegat
5、iveintegersOutput:Thereversalofeachinteger.-------------------------------------------------------------------*/#includeusingnamespacestd;voidprintReverse(unsignedn);/*-------------------------------------------------------------------Recursivelydisplaythedigitsofanonneg
6、ativeintegerinreverseorder--Exer.23.Precondition:n>=0Postcondition:Reversalofnhasbeenoutputtocout.-------------------------------------------------------------------*/intmain(){intn;for(;;){cout<<"Enteranonnegativeinteger(-1tostop):";cin>>n;if(n<0)break;cout<<"Reversalis:";print
7、Reverse(n);}}//--DefinitionofprintReverse()voidprintReverse(unsignedn){if(n<10)cout<8、ogramtotestpowerfunctionofExercis
8、ogramtotestpowerfunctionofExercis
此文档下载收益归作者所有