I am getting the following error while creating a function for creating a graph using adjaceny LIST representation:
error: invalid type argument of '->' (have 'int')
I have marked the line (in comments) where I am getting this error as //error. Below is the code:
typedef struct GRAPH
{
int V;
int E;
int *adj; //head pointer to the Linked List
} graph;
typedef struct NODE //Node of the Linked List
{
int vertexNumber;
struct NODE *next;
} node;
graph *adjListOfGraph()
{
int i,x,y;
node *temp;
graph *g;
g = (node *)malloc(sizeof(graph));
if(!g)
{
printf("Memory Error in creating the graph");
return;
}
scanf("Number of Vertex: %d, Number of Edges: %d", &g->V,&g->E);
g->adj=(node *)malloc(g->V *sizeof(node));
for(i=0;i<g->V;i++)
{
g->adj[i] = (node *)malloc(sizeof(node));
g->adj[i]->vertexNumber = i; //error
g->adj[i]->next = g->adj[i]; //error
}
for(i=0;i<g->E;i++)
{
scanf("Reading edges: %d %d", &g->V,&g->E);
temp = (node *)malloc(sizeof(node));
temp->vertexNumber = y;
temp->next = g->adj[x];
g->adj[x]->next = temp; //error
temp = (node *)malloc(sizeof(node));
temp->vertexNumber =y;
temp->next = g->adj[y];
g->adj[y]->next = temp; //error
}
return g;
}
Please have a look at lines commented as error. I have searched a lot and also tried replacing -> by . but useless.
Aucun commentaire:
Enregistrer un commentaire