Singly linked list, remove last node

I keep running into a program breaking error when my compiler reaches the function which calls

removeEnd();

can someone help me fix this please

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void TheNode::removeEnd()
{
	MyNode * current = head;
	MyNode * prev;
	prev = current;
	MyNode * garbage;
	while (current->next != NULL)
	{
		prev->next = current;
		current = current->next;
	}
	prev->next = current->next;
	garbage = current;
	delete garbage;
	current = prev->next;
	//current->next = NULL;
	//delete garbage;
	
	
	
}
Topic archived. No new replies allowed.