I was hoping to get some help on how to concatenate two linked lists in my doubly-linked list class. Specifically, how to properly call, from the driver file, a concatenate function located in the implementation file, including the correct way to pass the lists to the function. I already have a working doubly-linked list that includes operations such as insert, remove, etc. I decided not to include the entire code here because of the size. Also, I am hoping I have provided enough info to get help.
So far, I have in the implementation file:
Code:
template <class T>
void dlist<T>::concatenate(dlist<T> &list1, dlist<T> &list2) {
if( list1.Tail == NULL )
list1.Head = list2.Head;
else
list1.Tail->next = list2.Head;
if( list2.Head != NULL )
list1.Tail = list2.Tail;
}
Head and Tail are privately defined in the header file.
In the header file:
Code:
void concatenate(dlist<T> &list1, dlist<T> &list2);
And in the driver file where I am testing concatenate with two lists of integers:
Code:
dlist<int> list1, list2;
Since concatenate is a member function, I am fuzzy on how to call it, then dispay the newly appended list in the driver file.
Is a call like this suppose to work?
Code:
list2.concatenate(list1, list2);
I attempt to display the appended list, but it prints a loop of garbage. Any help would be greatly appreciated.