資源描述:
《 函數(shù)遞歸( function recursion)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、713函數(shù)遞歸(713functionrecursion)Itisawiseman,theremustbealoss;afool,therewillbeone.Energy-saving,nooneisknowntolitchi.Thebridgeisstillintheenergy-saving,energy-saving.Themightyriverflowseastward.wavesaretrulygreatmenthroughtheages.ThetwosidesofCastlePeakrelative,fromadayto.First,stackWheni
2、tcomestorecursivefunctions,bytheway,theconceptofthestack.Stackisabackwardinfirstout(push)andpop(POP)datastructure.Whentheprogramisrunning,thesystementersanobjectintothestackeachtime,andthenthestackpointermovesdownaposition.Whenthesystempopsupanobjectfromthestack,theobjectthathasrecently
3、enteredthestackwillpopup.Thenthestackpointermovesupaposition.Programmersoftenusethestackdatastructuretohandleprogrammingproblemsthatarebestsuitedtothedescriptionofbackwardfirstoutlogic.Thestackintheprogramdiscussedhereispresentineveryprogram.Itdoesnotrequireprogrammerstowritecodetomaint
4、ain,butrunsautomaticallybythesystem.Theso-calledsystemautomaticmaintenance,infact,isgeneratedbythecompilercode.Evenifyoudon'tseetheminthesourcecode,programmersshouldknowsomethingaboutit.Lookathowthestackintheprogramworks.Whenafunction(caller)callsanotherfunction(callee),theruntimesystem
5、willgivethecalleralltheargumentsandthereturnaddressontothestack,thestackpointerwillmovetotherightpositiontoaccommodatethesedata.Thelastentrytothestackisthecaller'sreturnaddress.Whenthecallerstartsexecuting,thesystempressesthecaller'sindependentvariableintothestackandmovesthestackpointer
6、downtoensurethatthereisenoughspacetostorealltheargumentsdeclaredbythecaller.Whenthecallerpressestheargumentintothestack,thecallerbuildstheparameterintheformofanindependentvariableinthestack.Othervariablesinsidethecallerarealsostoredinthestack.Becauseofthesestackoperations,thestackpointe
7、rhasmovedbelowalltheselocalvariables.However,thecallerrecordstheinitialstackpointerwhenitisbeginningtoexecute,anduseshimasareferencetoaccessthevariablesinthestackwithpositiveornegativeoffsetvalues.Whenthecallerisreadytoreturn,thesystempopsupalltheindependentvariablesinthestack,