recursive sorted merge sort linked list

I'm having trouble getting the functionality here if anyone can help. Basically I'm needing to pass in 3 head pointers to 3 different linked lists. I need to put the nodes in order from list 1 and 2 into list 3. I'm just not seeing my logic error here and need some help.

void SortedMergeRecur(Node*& xHead,Node*& yHead,Node*& zHead)
{
Node* temp = 0;
if(xHead == 0)
{
zHead = yHead;
yHead = 0;
}
else if(yHead == 0)
{
zHead = xHead;
xHead = 0;
}
else if(xHead != 0 || yHead != 0)
{
if(xHead -> data < yHead -> data)
{
zHead = xHead;
SortedMergeRecur(xHead -> link, yHead, zHead -> link);

}
else //if(xHead -> data > yHead -> data)
{
zHead = yHead;
SortedMergeRecur(xHead, yHead -> link, zHead -> link);

}
}
return;
}
1
2
//else if(xHead != 0 || yHead != 0)
  else if(xHead != NULL && yHead != NULL) //and 

Also you don't nullify the other pointers if you enter there.
Just put yHead = xHead = NULL; at the end of the function.
Topic archived. No new replies allowed.