infinite linked List unknown

Hi, this is a follow up on a previous question I had regarding an object we created to store a list of strings. The basic idea is put into code below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// strset.h
struct linkedList {
	std::string value;
	linkedList * node;
};

class strSet
{
private:
    linkedList* head;			// This is initially empty (when constructed)		
    bool isSorted () const;

public:
    strSet (); 			  	// Create empty set
    strSet (std::string s); 	 	// Create singleton set
    strSet (const strSet& rtSide);	// Copy constructor
    ~strSet ();			 	// Destructor
...
    strSet  operator +  (const strSet& rtSide);  // Union
    strSet  operator *  (const strSet& rtSide);  // Intersection
    strSet  operator -  (const strSet& rtSide);  // Set subtraction
    strSet& operator =  (const strSet& rtSide);  // Assignment

};


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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 // strset.cpp

...
strSet strSet::operator + (const strSet& rtSide) {
	int comparedValue;
	string thisString, rtString;
	linkedList *thisList = head;
	linkedList *rtList   = rtSide.head;
	linkedList *tempDelete;

	strSet *tempList = new strSet();
	if( (thisList != NULL) || (rtList != NULL) ) tempList->head = new linkedList;
	linkedList *newList = tempList->head;

	if( newList == NULL )  cout << "You got NULL TEMP HEAD!" << endl;

	while( (thisList != NULL) || (rtList !=NULL) ) { 

		if(thisList != NULL) thisString = thisList->value;
		if(rtList   != NULL) rtString   = rtList->value;
		if(head     != NULL) comparedValue = thisString.compare(rtString);


		if(thisList == NULL) comparedValue = 1;
		if(rtList   == NULL) comparedValue = -1;

		if( comparedValue == 0 ) {

			newList->value = thisString;
			newList->node = new linkedList;
			newList  = newList->node;			

			thisList = thisList->node;
			rtList   = rtList->node;

} else if( comparedValue > 0 ) { 
... 
	tempDelete = tempList->head;
	cout << "TempDelete head address: " << tempList->head << endl;

	while(tempDelete != NULL) {
		cout << "tempDelete address: " << tempDelete << endl;
		cout << "tempDelete node   : " << tempDelete->node << endl;
		tempDelete = tempDelete->node;
	}

	return *tempList;
}

...
strSet& strSet::operator = (const strSet& rtSide) { 
	nullify();
	linkedList *newList, *rtList = rtSide.head;
	int count = 0;
	if( rtSide.head == NULL ) { 
	        head = NULL; 
		return *this;
	}
	cout << "rtList head address: " << rtSide.head << endl;
	head = new linkedList;
	newList = head;
	do { 
		newList->node = new linkedList;
		newList->value = rtList->value;

		rtList         = rtList->node;
		cout << "rtList address: " << rtList << endl;
		cout << "rtList value : " << rtList->value << endl;
		if(rtList == NULL) cout << "RT LIST HAS A NULL HEAD!" << endl;
		newList        = newList->node;
		count ++;
	}while( rtList != NULL  && count < 10);

	delete newList;
	newList = NULL;
	return *this;
}


1
2
3
4
 // main.cpp
...
	tempSet = (tempSet + tempSet2);
...


This is the output from the main code (particularly adding the two sets together)
The first set is null, and the second set just has one string.
strSet tempSet;
strSet tempSet2("a") <--- a string "a"
tempSet = tempSet + tempSet2; :

TempDelete head address: 0xda00b0
tempDelete address: 0xda00b0
tempDelete node   : 0xda00d0
tempDelete address: 0xda00d0
tempDelete node   : 0
rtList head address: 0xda00f0
rtList head address: 0xda00f0
rtList address: 0xda0110
rtList value : 
rtList address: 0xda0130
rtList value : a
rtList address: 0xda0150
rtList value : 
rtList address: 0xda0170
rtList value : a
rtList address: 0xda0190
rtList value : 
rtList address: 0xda01b0
rtList value : a
rtList address: 0xda01d0
rtList value : 
rtList address: 0xda01f0
rtList value : a
rtList address: 0xda0210
rtList value : 
rtList address: 0xda0230
rtList value : a


My main question is, why does the object that I am returning have a finite linkedList, yet the same one I pass through the = operator as a parameter, has an infinite linkedList?

Topic archived. No new replies allowed.