Listnodes and pointers

I need to write a function to concatenate a listnode object onto another listnode object. I'm given:

struct Listnode
{ double value;
Listnode *next;
};

Listnode *ListCon(Listnode *list1, Listnode *list2)

This is what I have added:
{
if (list1 == NULL)
{
cout << "Listnode 1 does not exist";
return 0;
}
while (list1 != NULL)
list1 = list1->next;
if (list2 == NULL)
{
cout << "Listnode 2 does not exist";
return list1;
}
list1->next = list2;
return list1;
}

Does this code look good to you?
please use code tags it will be difficult for everyone to read
Did you run your program? i don't think you are doing right. concatenaion works like list1+=list2.

If you really need a reference on how to get started here you go.
http://www.cplusplus.com/forum/beginner/39709/
Last edited on
You are dereferencing a NULL pointer...
How do I use code tags? I'm new to forums. I'm doing problems to prep for a final. I was hoping to avoid having to write a whole program.
Last edited on
when you are writing just highlight the code and from the format menu click on <> icon.
Last edited on
I did some more looking around and found some code similar enough to mine. Using += to concatenate nodes is not in my book. I'll do some more looking.
Topic archived. No new replies allowed.