I need to create a function that takes two lists as parameters and creates a new list by concatenating the first list with the second list. So far I have
I am having trouble with my pointers, and am also unsure if I require a loop, or how I would even go about creating one that combine two lists together. Much help appreciated, and yes this is a .h
It depends. Do you want your old lists to remain the same? If so, that's going to be difficult, as the Linked part happens inside the elements, not inside the Lists.
If you don't need the old lists (which should be the case in most applications), you only need these steps:
1) newlist.head = oldlist1.head; (Set starting point of new list on first point of an old list)
2) oldlist1.last->next = oldlist2.head; (Link last of oldlist1 to first of oldlist2)
3) Delete oldlist1 and oldlist2.
The easiest (best?) way to do this is through a constructor that accepts two LinkedList objects as parameters. The way you did it is also an option, but I recommend against it.
For step 3, do mind possible side-effects caused by your deconstructors. If your linked list takes care of its own nodes through recursive deletion, you'll also be deleting the content of your new list.