I am trying to implement graph using adjacency list ,according to my knowledge that i have learnt so far if i created variable array
pointer to struct adjlistnode
of size v*sizeof(struct adjlistnode)
thin i can store the addresses of v struct adjlistnode
type node in each index of array
Means that each index of array will point to the node of type struct adjlistnode
but when i am assigning G->array[i]=NULL
it gives me error
||=== Build: Debug in teeest (compiler: GNU GCC Compiler) ===|
C:\Users\Mahi\Desktop\DATA STR\teeest\main.c||In function 'creategraph':|
C:\Users\Mahi\Desktop\DATA STR\teeest\main.c|59|error: incompatible types when assigning to type 'struct adjlistnode' from type 'void *'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
why i am not able to assign NULL to index of array
what should i do if i want to access adjacency list like using G->array[i]
=first node address adjacent to i
th vertex of graph and later i will add another node if needed
struct adjlistnode{
int dest;
struct adjlistnode* next;
};
struct graph{
int V;
struct adjlistnode* array;
};
struct adjlistnode* getnewnode(int dest){
struct adjlistnode* newnode =(struct adjlistnode*)malloc(sizeof(struct adjlistnode));
newnode->dest=dest;
newnode->next=NULL;
return newnode;
}
struct graph* creategraph(int v){
struct graph* G=(struct graph*)malloc(sizeof(struct graph));
G->V=v;
G->array=(struct adjlistnode*)malloc(v*sizeof(struct adjlistnode));
for(int i=0;i<v;i++){
G->array[i] =NULL;
}
return G;
}