Checkpoint 4.9.1.
Refer to the
nLines
function below. It is the same as the nLines
function defined on the previous page. How many instances of nLines
would there be in the stack diagram if we begin with n = 4?
void nLines(int n) {
if (n > 0) {
cout << endl;
nLines(n + 1);
}
}
- 3
- If nLines could reach its base case, it cannot be done in 3 function calls.
- 4
- If nLines could reach its base case, it cannot be done in 4 function calls.
- 5
- If nLines could reach its base case, it could be done in 5 function calls, but does it ever reach the base case?
- infinite
- The nLines function never reaches its base case, so the stack diagram would be infinitely long.