I\'m trying to create a function that would print out my link list recursively, but I\'m having trouble doing that, because recursion is just hard.
This is the funct
Your recursive version needs an input:
void List::PrintListRecursively(Node* curr)
{
if (curr==NULL)
{
cout << "\n";
return;
}
cout << curr->data <<endl;
PrintListRecursively(curr->next);
}
Which you would then call using the head pointer:
list.PrintListRecursively(list.GetHead());
Or you could create a version that takes no parameters:
void List::PrintListRecursively()
{
PrintListRecursively(GetHead());
}
Which calls the version that takes the pointer parameter.