Question is answered, but I would like to add my points.
I will always prefer if(pointer)
instead of if(pointer != NULL)
and if(!pointer)
instead of if(pointer == NULL)
:
Less chances to write a buggy code, suppose if I misspelled equality check operator ==
with =
if(pointer == NULL)
can be misspelled if(pointer = NULL)
So I will avoid it, best is just if(pointer)
.
(I also suggested some Yoda condition in one answer, but that is diffrent matter)
Similarly for while (node != NULL && node->data == key)
, I will simply write while (node && node->data == key)
that is more obvious to me (shows that using short-circuit).