i got 3 linked list and union function
a b and result are lists i want to fill result list with elements but it is always empty.
main is result.UnionSets(a,b) function is
void UnionSets(linkedlist & l1, linkedlist & l2)
{
node<type> *temp= l1.tail;
if(temp!=NULL)
{
while(temp->next!=tail)
{
AddNode(temp->data);
temp=temp->next;
}
}
temp=l2.tail;
if(temp!=NULL)
{
while(temp->next!=tail)
{
AddNode(temp->data);
temp=temp->next;
}
}
}
I need to assume some things about your linked list implementation. If my assumptions are wrong, then my answer is wrong, too.
You are initializing your
temppointers to thetailelement of their linked lists. The typical nomenclature is to start atheadand work towardstail. Also, it is typical that the in final node has NULL as its next pointer.You are comparing nodes of one linked list to nodes on a different linked list. Are the linked lists actually cross-linked? Or are they actually independent of each other?
Taking those two points into account, try this: