Chapter 18: Prelab Assignment
Recursion | 455
Name __________________________________________ Date _______________________
Section _________________________________________
Exercise 1: Fill in the following chart showing the value of the variable n at the beginning of
each execution of function Factorial, starting with the nonrecursive call Factorial(5). Fill in
the third column with the function value returned at the completion of the execution of that call.
Call n Function Value Returned
Nonrecursive Call _______ ___________________
1st Recursive Call _______ ___________________
2nd Recursive Call _______ ___________________
3rd Recursive Call _______ ___________________
4th Recursive Call _______ ___________________
5th Recursive Call _______ ___________________
Exercise 2: Fill in the chart showing the value of the variable first at the beginning of each
execution of function SumArrays. Fill in the third column with the function value returned at the
completion of the execution of that call.
Call first Function Value Returned
Nonrecursive Call _______ ___________________
1st Recursive Call _______ ___________________
2nd Recursive Call _______ ___________________
3rd Recursive Call _______ ___________________
4th Recursive Call _______ ___________________
5th Recursive Call _______ ___________________
6th Recursive Call _______ ___________________
7th Recursive Call _______ ___________________
78828_CH18_DaleLab 5/22/09 7:55 AM Page 455
Exercise 3: Fill in the chart showing the value of the variable listPtr at the
beginning of each execution of function NumItems, where listPtr is as shown
below. Refer to listPtr by an arrow to the value in the node. For example, 3 refers
to the node containing the value 3. Fill in the third column with the function value
returned at the completion of the execution of that call.
Call listPtr Function Value Returned
Nonrecursive Call _______ ___________________
1st Recursive Call _______ ___________________
2nd Recursive Call _______ ___________________
3rd Recursive Call _______ ___________________
4th Recursive Call _______ ___________________
456 | Chapter 18
78828_CH18_DaleLab 5/22/09 7:55 AM Page 456

Get A Laboratory Course in C++, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.