Hello so I’m trying to implement graph data structure in c++ with adjacency list. I am using structures for that.

```
struct node{
int src;
node*next;
};
struct Graph{
int vertex;
node**adj; //for storing head pointers of adjacency list
};
```

Now here how do I allocate memory dynamically for storing V(vertex) no. of head pointers of adjacency lists in adj(of graph structure). I tried something like

```
graph*g=new graph();
*(g->adj)=new node*[v]; //v is no of vertices
```

But I think its wrong.

And also how to access this adj(of graph)?

I tried like this for adding an edge between two vertex.

```
temp->next=*(g->adj[src]) //here temp is newly created node pointer and g is a graph pointer.
*(g->adj[src])=temp; //src is the source vertex
```

I think the syntax is incorrect.

Please help.