We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
No, you need this. The first one handles if they are both NULL. The second handles if only one is NULL. If we ask about if one is NULL, without knowing about the second, we would need yet another if statement inside of it.
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
First check (headA == NULL && headB == NULL) is not necessary because the following two will handle it.
No, you need this. The first one handles if they are both NULL. The second handles if only one is NULL. If we ask about if one is NULL, without knowing about the second, we would need yet another if statement inside of it.
I disagree. If both are NULL, then
will trigger and return NULL since that is what headB equals to. And we did expect NULL, so the case of two NULLs is indeed redundant.
it will handle it because if both are null when you check the first list it runs true and return second which is null itself so null is returned