Recursion for Lists

Hello once again haha. Here we are again with Recursion you would think that by now I would have gotten it but I am having so much trouble with recursion.

So I have created two linked lists. I need to use a recursive function to do the following:

Assuming that list one isn't empty append list 2 to list one. return the pointer to list one. If list one is empty then return the pointer to list two.

I am just stuck really.

Any guidance would be great!
closed account (E0p9LyTq)
Are you using an STL container for your lists, or a user created linked list?

If using an STL container, such as list, use the container's empty member function.

http://www.cplusplus.com/reference/list/list/empty/

For user created linked list, it's up to you to figure out if the list is empty or not.
I am using *list1 and *list2 etc in order to create the list. I created an array of various numbers and set them to the lists in order to populate the lists.

This is what I have:

1
2
3
4
5
node *append(node *list1, node*list2)
{
     if(next==0)return 0;
     else append(list1,list2);
}
closed account (E0p9LyTq)
By the source you've included it looks like a custom created linked list.

You need to create a node class function to programmatically determine if your list objects are empty.

How you do that is up to you. Look at how it is done in an STL container class.
Topic archived. No new replies allowed.