What is the the difference between the following implementations of the length function?
int length(List l)
{
int len = 0;
while(l != NULL) {
l = l->next;
len++;
}
return len;
}
int length(List l)
{
if(l == NULL) return 0;
return 1 + length(l->next);
}
int length(List l)
{
int length-helper(List l, int len)
{
if(l == NULL) return len;
return length-helper(l->next, len+1);
}
return length-helper(l, 0);
}