Hi, their is part of a homework problem which I seem to be stuck on. It asks what are the logic errors in a program if the function defined is supposed to return the legnth of a linked list.
The function is:
I am having trouble seeing what is wrong with it...It seems as it is set to increment the int variable size by one while the pointed variable cur is not null. cur is then set to be the next value. This would continue until cur had nothing left thus making it null and stopping the while loop.Code:int length(NodePtr *Head){ int size = 0; NodePtr *cur; while(cur != NULL){ size++; cur = cur->next; } }
Help please!