资源描述:
《函数递归( function recursion)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、713函数递归(713functionrecursion)Itisawiseman,theremustbealoss;afool,therewillbeone.Energy-saving,nooneisknowntolitchi.Thebridgeisstillintheenergy-saving,energy-saving.Themightyriverflowseastward.wavesaretrulygreatmenthroughtheages.ThetwosidesofCastlePeakrelative,froma
2、dayto.First,stackWhenitcomestorecursivefunctions,bytheway,theconceptofthestack.Stackisabackwardinfirstout(push)andpop(POP)datastructure.Whentheprogramisrunning,thesystementersanobjectintothestackeachtime,andthenthestackpointermovesdownaposition.Whenthesystempopsupa
3、nobjectfromthestack,theobjectthathasrecentlyenteredthestackwillpopup.Thenthestackpointermovesupaposition.Programmersoftenusethestackdatastructuretohandleprogrammingproblemsthatarebestsuitedtothedescriptionofbackwardfirstoutlogic.Thestackintheprogramdiscussedhereisp
4、resentineveryprogram.Itdoesnotrequireprogrammerstowritecodetomaintain,butrunsautomaticallybythesystem.Theso-calledsystemautomaticmaintenance,infact,isgeneratedbythecompilercode.Evenifyoudon'tseetheminthesourcecode,programmersshouldknowsomethingaboutit.Lookathowthes
5、tackintheprogramworks.Whenafunction(caller)callsanotherfunction(callee),theruntimesystemwillgivethecalleralltheargumentsandthereturnaddressontothestack,thestackpointerwillmovetotherightpositiontoaccommodatethesedata.Thelastentrytothestackisthecaller'sreturnaddress.
6、Whenthecallerstartsexecuting,thesystempressesthecaller'sindependentvariableintothestackandmovesthestackpointerdowntoensurethatthereisenoughspacetostorealltheargumentsdeclaredbythecaller.Whenthecallerpressestheargumentintothestack,thecallerbuildstheparameterinthefor
7、mofanindependentvariableinthestack.Othervariablesinsidethecallerarealsostoredinthestack.Becauseofthesestackoperations,thestackpointerhasmovedbelowalltheselocalvariables.However,thecallerrecordstheinitialstackpointerwhenitisbeginningtoexecute,anduseshimasareferencet
8、oaccessthevariablesinthestackwithpositiveornegativeoffsetvalues.Whenthecallerisreadytoreturn,thesystempopsupalltheindependentvariablesinthestack,