I am trying to merge two linked lists. It works correctly when I write this:
if(p->data < q->data){
third = p;
last = p;
p = p->next;
third->next = NULL;
}else{
third = q;
last = q;
q = q->next;
third->next = NULL;
}
But it doesn't work correctly when I write this:
if(p->data < q->data){
third = p;
last = p;
third->next = NULL;
p = p->next;
}else{
third = q;
last = q;
third->next = NULL;
q = q->next;
}
I am wondering why. Can anyone explain? third: Pointer from where merged list starts. p, q: Pointers to 2 lists. last: Pointer which connects further elements.