COAL Lec 15 Parameter Passing Through Stack and Recursion
This document discusses parameter passing through the stack and recursion. It provides an example of a recursive factorial procedure that passes the parameter N down the stack on subsequent recursive calls, decrementing it by 1 each time until the base case of N=1 is reached. It then returns back up the stack multiplying the intermediate results to calculate the final factorial value. The homework is to review an example of finding the maximum value on page 359.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
67 views5 pages
COAL Lec 15 Parameter Passing Through Stack and Recursion
This document discusses parameter passing through the stack and recursion. It provides an example of a recursive factorial procedure that passes the parameter N down the stack on subsequent recursive calls, decrementing it by 1 each time until the base case of N=1 is reached. It then returns back up the stack multiplying the intermediate results to calculate the final factorial value. The homework is to review an example of finding the maximum value on page 359.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5
Procedures
Parameter passing through Stack and Recursion
Parameter through Stack • BP register • RET n PROCEDURE FACTORAL (input: N, output: Result) If N = 1 then Result = 1 Else call FACTOTAL (input: N-1, output: Result) Result = N * Result END_IF RETURN Home work • Find MAX example on page 359