I was trying to implement graph using an adjacency list.While initializing head as NULL in the for loop in CreateGraph method, head is being reffered using '.' instead of '->'. I cannot understand the difference. When should we use '.' and when '->'. And why do it gives an error , when I use -> operator for head.
struct AdjListNode
{
int dest;
struct AdjListNode* next;
};
struct AdjList
{
struct AdjListNode *head; // pointer to head node of list
};
struct Graph
{
int V;
struct AdjList* array;
};
// A utility function to create a new adjacency list node
struct AdjListNode* newAdjListNode(int dest)
{
struct AdjListNode* newNode =
(struct AdjListNode*) malloc(sizeof(struct AdjListNode));
newNode->dest = dest;
newNode->next = NULL;
return newNode;
}
// A utility function that creates a graph of V vertices
struct Graph* createGraph(int V)
{
struct Graph* graph = (struct Graph*) malloc(sizeof(struct Graph));
graph->V = V;
// Create an array of adjacency lists. Size of array will be V
graph->array = (struct AdjList*) malloc(V * sizeof(struct AdjList));
// Initialize each adjacency list as empty by making head as NULL
int i;
**for (i = 0; i < V; ++i)
graph->array[i]->head = NULL;**
return graph;
}