资源描述:
《 函数递归( function recursion)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、713函数递归(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,