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

}

 Write a recursive function that calculates and returns the length of a linked list.SolutionHi, You have not posted your linked list code. And you asjed for onl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site