Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ I have a small question in this piece of code. I wanna add that if there are

ID: 3866860 • Letter: C

Question

C++ I have a small question in this piece of code. I wanna add that if there are no nodes return -1; and then in main i can call the "display error" Please if you do not know don't answer it. and no it is not as simple as:

if (node == NULL)
    {
    return -1 void largest is no good;
    } //This would be wrong and totally wrong so please chegg answerers don't answer if you do not know

int IntList::numNodes(ListNode* node)
{
int count = 1;
if (node == NULL)
{
  return 0;
}
else
{
  count += numNodes(node->next);
  return count;
}
}

Explanation / Answer

int IntList::numNodes(ListNode* node)
{

if (node == NULL)
{
  return -1; // Finally If There are No Nodes and if it is the First Node also this will be returned to main
}
else
{
return (2+numNodes(node->next));//As -1 is returned we have given 2+ to nullify the -1 value returned when NULL
}
}