Monday, November 21, 2005

Counting a list recursively

If there is an iterative way, there must be a recursive way.



int count_rec(LINK head)
{
        if (head == NULL)
                return 0;

        else
                return (1 + count_rec(head -> next));
}

No comments: