Write a recursive function that calculates and returns the l
Write a recursive function that calculates and returns the length of a linked list.
Solution
Hi, You have not posted your linked list code.
And you asjed for only recurive method implementation.
Please find my code:
// recursive function to calculate length of linked list
// assuming that head is first node of linked list
int lengthOfLinkedListRec(Node *head){
// base case
if(head == NULL){
return 0;
}
return (1 + lengthOfLinkedListRec(head->next)); // calling recursively
}
