Segmentation fault when randomizing a LLL

I'm trying to randomize a LLL.

card_list is a LLL, and randomize is suppose to basically shuffle the contents.
I'm running into a segfault when I progress previous->next = current->next;

This function takes a number, (number is randomized and % by the size of the LLL so it always spits out a number equal or smaller to the list size) I progress to the number in the list with a previous pointer. Once at the location I copy the node, reinsert the copy into the front of the list and then delete the node. I have this exact function working in a different program, but for some reason it's segfaulting now.

Maybe previous->next = current->next is pointing to a NULL pointer, I'm not sure.

Any help would be valued.


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

void card_list::randomize_list(int num) {

	int zero = 0;

	if(!head)
	{
		return;
	}

	card_node * previous = NULL;
	card_node * current = NULL;
	current = head;

	while(zero != num)
	{
		previous = current;
		current = current->next;
		++zero;
	}
	
	copy_a_card(current); //create this function
	
	insert(current->data);

	previous->next = current->next; //Segmentation fault

	delete current;
}
http://www.cplusplus.com/forum/general/112111/

> Maybe previous->next = current->next is pointing to a NULL pointer, I'm not sure.
¿why don't you look?
Topic archived. No new replies allowed.