samedi 5 septembre 2020

Is this a way to check whether or not a LinkedList node is initialized?

I am trying to create an insert-at-end function for a linked list class. I was having some trouble, so I looked up some code and found the following:

if (!start) // empty list becomes the new node
{
    start = newNode;
    return;
}

This seems to be a check to make sure that if the user uses the function with an empty list, the newly created "ending" node, newNode, becomes the start node. But, what does if (!start) do? (start is the head node).

Aucun commentaire:

Enregistrer un commentaire