# Graph Adjacency List Representation in C

Any Body have Short and Simple Graph Adjacency List Representation code in C.

// A C Program to demonstrate adjacency list representation of graphs

``````#include <stdio.h>
#include <stdlib.h>

// A structure to represent an adjacency list node
{
int dest;
};

// A structure to represent an adjacency liat
{
};

// A structure to represent a graph. A graph is an array of adjacency lists.
// Size of array will be V (number of vertices in graph)
struct Graph
{
int V;
};

// A utility function to create a new adjacency list node
{
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

// Initialize each adjacency list as empty by making head as NULL
int i;
for (i = 0; i < V; ++i)

return graph;
}

// Adds an edge to an undirected graph
void addEdge(struct Graph* graph, int src, int dest)
{
// list of src.  The node is added at the begining

// Since graph is undirected, add an edge from dest to src also
}

// A utility function to print the adjacenncy list representation of graph
void printGraph(struct Graph* graph)
{
int v;
for (v = 0; v < graph->V; ++v)
{
while (pCrawl)
{
printf("-> %d", pCrawl->dest);
pCrawl = pCrawl->next;
}
printf("\n");
}
}

// Driver program to test above functions
int main()
{
// create the graph given in above fugure
int V = 5;
struct Graph* graph = createGraph(V);

// print the adjacency list representation of the above graph
printGraph(graph);

return 0;
}
``````

Source: geeksforgeeks

#define pb push_back
vector weg[MAXN];