main()
{
head = (node*)malloc(sizeof(node));
create(head);
print(head);
c = count(head); //See here you are sending the actual node, which is head.
}
int count(node* C_list)
{
if(C_list->next==NULL) //-->Here the if condition is checking for the next node (head->next) whether it is null or not.
return(0); //-->If the next node is null, it means no nodes are there. So returning 0.
else
{
return(1+count(C_list->next));
}
}
Now the tricky part is the return line, in which you are passing C_list->next
i.e., head->next
to the count function. And now after recursion, in the above if
condition it checks for the next node address i.e., head->next->next
and it goes on until the node is null
, this way the next address is getting passed for the recursive function. Hope this might have helped you.
1
solved Linked List quetion [closed]