Thanks for the quick reply
I used some printf statements to see what was in current and current->to_vertex, it seems that it points to the memory address rather than the actual value?
Firstly, I constructed the linked list like this:
Code:
for (i=0; i<n_vertices; i++)
{
scanf("%d", &e[i]);
g[i] = create();
for(j=0; j<e[i]; j++)
{
scanf("%d", &to);
insert_at_front(to, g[i]);
}
where 'to' is a scanned int, and create() is:
Code:
node_ptr create(void)
{
node_ptr list = (node_ptr) malloc(sizeof(struct node));
list->next = NULL;
return list;
}
and insert_at_front (with n equal to 'to' and list equal to g[i]) is:
Code:
void insert_at_front(int n, node_ptr list)
{
node_ptr new_node = (node_ptr) malloc(sizeof(struct node));
new_node->to_vertex = n;
new_node->next = list->next;
list->next = new_node;
}
When I run it, I get the following output:
The value of current is: 135536
The value of current->to_vertex is: 137088
Segmentation fault( core dumped)
I really am stuck on this