linked list copy constructor help!!! urgent

Here is my code
it runs but after display result, it announce error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
template <class T> 
class LINKED_LIST
{
private:

	struct ListNode
	{
		T data; 
		ListNode *next; // pointer to next node
	};

	unsigned int size; // number of node in list
	ListNode *head; 

public:

	LINKED_LIST(); 
	LINKED_LIST(const LINKED_LIST &aList); // copy constructor
	// operations
	bool isEmpty();
	int insert(unsigned int index, T newItem); // insert after “index”
         ........
}; 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template <class T>
LINKED_LIST<T>::LINKED_LIST(const LINKED_LIST &aList)
{
	size = 0;
	head = NULL;
	ListNode *p = aList.head;
	unsigned int i = 0;
	while (p != NULL)
	{
		this->insert(i,p->data);
		p = p->next;
		i++;
	}

}


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
template <class T>
int LINKED_LIST<T>::insert(unsigned int index, T newItem)
{

	if (index > size) return 0; // fail
	else 
		if (index == 0) // addhead
		{
			if (head == NULL) 
			{
				ListNode *pNewNode = new ListNode;
				pNewNode->data = newItem;
				pNewNode->next = NULL;
				head = pNewNode;
				size++;
				return 1;
			}
			else
				{	
					ListNode *pNewNode = new ListNode;
					pNewNode->data = newItem;
					pNewNode->next = NULL;
					pNewNode->next = head;
					head = pNewNode;
					size++;
					return 1;
				}
			
		}
		else
			if (index == size) //addtail
			{
				ListNode *pNewNode = new ListNode;
				pNewNode->data = newItem;
				pNewNode->next = NULL;
				ListNode *p = head;
				unsigned int pos = 1;
				while (pos != index)
				{
					p = p->next;
					pos++;
				}
				p->next = pNewNode;
				size++;
				return 1;
			}
			else
				{
					ListNode *pNewNode = new ListNode;
					pNewNode->data = newItem;
					pNewNode->next = NULL;
					ListNode *p = head;
					unsigned int pos = 1;
					while (pos != index)
					{
						p = p->next;
						pos++;
					}

					pNewNode->next = p->next;
					p->next = pNewNode;
					size++;
					return 1;
				}
	return 0;
}
i almost done my exercise , only one left ---->>> this copy constructor, plz help
it run!!!
Topic archived. No new replies allowed.