Reputation: 3
I have this function that takes in two Doubly Linked list and puts them into this doubly linked list, and I am having no problem with the merging. The problem that I am having is that the two linked lists used as parameters need to be empty when it is over, but I cannot figure out how to do that.
void merge(DLinkedList a, DLinkedList b)
{
DNode* atemp = a.header;
DNode* btemp = b.header;
while(atemp != NULL)
{
insertOrderUnique(atemp->data);
atemp = atemp->next;
}
while(btemp != NULL)
{
insertOrderUnique(btemp->data);
btemp = btemp->next;
}
}
Upvotes: 0
Views: 93
Reputation: 519
I am not entirely sure what your DLists look like, but you should not copy them. So instead of:
void merge(DLinkedList a, DLinkedList b)
write:
void merge(DLinkedList& a, DLinkedList& b)
or:
void merge(DLinkedList* a, DLinkedList* b)
Upvotes: 1