I want to write some basic code on graph like DFS, BFS but before that I am coding graph representation in adjacency list, and some basic functions like readgraphfrommatrix
. (This will initialize graph from adjacency matrix which is easier to supply as input to test the program.)
A vertex can have some info like name (say name of town), an edge can have some info like weight.
Does below code look decent enough or there are more standard recognized code snippets for adjacency list representation of graphs?
struct edge
{
char *data;
}
struct vertex
{
char *data;
};
struct node
{
int vertexnumber;
struct node *next;
}
struct graph
{
int nvertex,nedges; //
struct vertex **V; // in main, I will malloc depending on input to have sth like struct vertex V[nvertex];
struct edge **E //to have like struct edge E[nedges];
struct node **list ; // to have like struct node* list[nvertex];
}