I know people usually ask this question the other way round, but I have the following problem: I have this iterative function which counts all the nodes in a circular doubly link list containing the data value 20. Now, how do I make this recursive, what will be the base case (terminating case) for the recursive function? Any help is appreciated:
int count(node *start)
{
int c;
c = 0;
if(start == NULL)
return 0;
if((start->roll_no) == 20)
c = 1;
node *current = start;
while(current->next != start)
{
if((current->next->roll_no) == 20){
c++;
}
current = current->next;
}
return c;
}
See Question&Answers more detail:os