CS210 Lab: Recursion Postlab


Postlab Exercise:

This postlab exercise is broken down into two parts.

Part 1

Use the following function to answer Questions 1 and 2.
int Puzzle (int base, int limit)
{
	if (base > limit)
		return -1;
	else
		if (base == limit)
			return 1;
		else
			return base* Puzzle(base+1, limit);
}
  1. Identify the following:
    1. the base case(s) of the function Puzzle
    2. the general (recursive) case(s) of the function Puzzle

  2. Show what would be written by the following calls to the recursive function Puzzle
    1. cout << Puzzle(20,5);
    2. cout << Puzzle(3,6);
    3. cout << Puzzle(8,8);

Part 2

This question is based on the lab exercise that you just completed.
  1. Another approach to recusively removing 'c' would be to return an address of the next node in sequence (that isn't a c). In this case, you don't have to pass by reference and the prototype will look like the following:
    template < class DT >
    ListNode<DT> * List<DT>:: cRemoveSub ( ListNode<DT> *p )
    	
    Write the code to complete this function.
Back to Recursion Lab click here

CS Dept Home Page
CS Dept Class Files
CS210 Class Files

Copyright: Department of Computer Science, University of Regina.