Recursion (computer science): Difference between revisions

Content deleted Content added
massive cleanup, rewrite examples, rm lots of redundancy; but it still needs a major rewrite
Tcsetattr (talk | contribs)
Tail-recursive functions: fix example's wrong return type and infinite recursing
Line 111:
Notice that a single function may be both tail-recursive and augmenting recursive, such as this function to count the odd integers in a linked list:
 
structint node *count_odds(struct node *head)
{
if (head == NULL)
return 0;
if (head->data % 2 == 1)
return count_odds(head->next) + 1; /* augmenting recursion */
return count_odds(head->next); /* tail recursion */
}