typedef struct vertex{
int num;
struct vertex *next;
} Vertex;
Vertex *adj[1];
void buildList(){
Vertex *v=NULL;
Vertex *t=NULL;
v = malloc(1*sizeof(*v));
v->num = 1;
adj[0] = v; //a NODE with value 1
t = v;
v = malloc(1*sizeof(*v));
v->num = 1;
t->next = v; // and ANOTHER NODE but it should be the SAME NODE with the above one
t = v;
//v = malloc(1*sizeof(*v));
//v->num = 1;
//t->next = adj[0]; // causes infinite loop...
//t = v;
}
The expected output is a node with value 1 having itself in its adjacency list, an output like 1 -> 1.
Here my problem is it looks like I have two different nodes. When I made a change on one of them the other doesn’t change, acting like an another node.
For instance after building the list if I change the value of the node I should get an output like 3 -> 3. But I get 3 -> 1. The change on the node doesn’t affect the other one. When I try to point adj[0] to t->next however I get an infinite loop…
It’s not entirely clear to me what you want. If you want a
Vertexpointing to itself, it’s simplyCan you clarify in what way this is not what you want?