|
Suppose that you want doubleAll(L) to modify the items in list L by doubling each. For example, if L is [1, 3, 5], then after doing doubleAll(L), L will contain [2, 6, 10]. The cases are simple.
If L is empty there is nothing to do.
if L is not empty then double its head and call doubleAll on its tail.
void doubleAll(List L) { if(L != NULL) { L->head = 2 * L->head; doubleAll(L->tail); } }
Is the definition of doubleAll tail-recursive? Answer
|