I have come to a problem where I try to use while loop on linked list.
I have two linked lists, namely temp and graph. I am using a while loop to do tasks while(temp != NULL). To move on in each of the loop, I am assigning temp = temp->link. However, this code does not compile. I realize that recursive function could be a solution, but the function is actually way more complicated that I don't think recursive would be such a good idea. By the way, graph is already a built linked list. Thanks in advance!
P.S. It is part of homework.
temp = graph->link;
while(temp!=NULL){
if(stack->link == NULL){
stack->link = (node_pointer)malloc(sizeof(graph));
stack->link->weight = temp->weight;
stack->link->vertex = temp->vertex;
}
temp = temp->link; //Here is the problem.
}
edit:
stack and graph are both arrays of linked list:
typedef struct node *node_pointer;
struct node{
int vertex;
int weight;
int visited;
struct node *link;
};
node_pointer graph[50];
node_pointer stack[50];
node_pointer temp;
However, this code does not compile.I don't understand this statement. You don't have any sintatic problem.Unhandled exception at 0x00d716c2 in graph.exe: 0xC0000005: Access violation reading location 0xcdcdcdd9.