int Link :: find_r(node *pNode)
{
node *cur = head;
if(cur->next != NULL)
return find_r(cur->next);
elsereturn cur->data;
}
Can someone please help me? Where is the segmentation fault here? I figure when the function is calling cur->next at some point as a parameter. its jumping past the linked list, but I can not figure out how to fix it.
I think this would lead to infinite recursion (oh-THAT may cause a seg. fault).
Your function does not use the node* passed to it (pNode). It just keeps using head over and over and over...
Try this and see what happens:
1 2 3 4 5 6 7 8 9
int Link :: find_r(node *pNode)
{
if(pNode->next != NULL)
return find_r(pNode->next);
elsereturn pNode->data;
}
I think you would pass head to the function when you call it. This provides it with the starting point in the list. eg. if myList is an instance of a list
int lastValue = myList.find_r( myList.head );// looks like the function finds the last data value