I have this popFront function for a linked list:
Node* popFront(Node* list)
{
Node* returnMe = (Node*)malloc(sizeof(Node));
Node* oldHead = list;
returnMe->mData = list->mData;
if (list->mNext != NULL)
list = list->mNext; // This line is definitely called
else
list = blankNode; // And not this one
free(oldHead);
return returnMe;
}
But whenever I call it like this:
Node* list = buildList(10);
Node* oldHead = popFront(list);
printInfo(list);
‘oldHead’ is correct but ‘list’ still has its first Node.
If you want the variable
listto change, you need to pass it by pointer. Since the value of list isNode*, you would need to pass to have the signature of popFront beNode* popFront(Node **list).