Need help combined 2 lists into 1 newlist. Almost there.

I am trying to combine list1 and list2 into newlist but am having a few errors. After these 2 lists combine, their values will be zero

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

LinkedList catList(LinkedList &list1, LinkedList &list2)
{
	ListNode *nodePtr;
	LinkedList newList;
	newList = catList(list1, list2);

	newList = createList();

	*nodePtr -> next;

	while(nodePtr->next !=NULL)
	{
		*nodePtr list1.data;
	}

	

	newList = list1;

	list1.size = 0;
	list2.size = 0;

	list1 =NULL;
	list2 = NULL;

	return newList;
}






Any help would be appreciated, thank you.
There are some thinks I don't properly understand:
1st: when you combine those, shall the values be 0 or not? (usually not, but from your question it looks like... My english is somehow poor)
2nd: what does it means row 6? It seems to me this would be infinite recursion...
3rd- I need more details on the implementation of linkedList. Which methods are available? which data member do they contains?

And, related to your post, I have more questions:
should list1 and list2 survive to this comination or not?
I mean if list1 contains 1,2,3 and list2 4,5 and list3 = catList (list1,list2),
list3 should contain (1,2,3,4,5), but how about list1? should it contain 1,2,3? should it be empty? should exist after concatenation?
If they must be empty (as it seems from row 24 and 25), why do you need to make a copy of the entire list?

Wouldn't be enough to assign to the pointer of the last ListNode of list1 the first node of list2?
Did you defined operator= to make the compiler accepting list1=NULL? list1 is an object of type list. NULL is (mostly) == 0 and is used for pointers.

about row 8: Did you already defined operator = for your LinkedList? Does it make a copy or is it creating aliases?
Topic archived. No new replies allowed.