C Graph implementation with adjacency list representation using structures: Data Structure Tutorial 1
This is a quick tutorial for implementing graph data structure with adjacency list representation. Once I was looking on the web to have a simple introductory tutorial on graphs, but unfortunately couldn’t find one simple enough. So I decided to write this. In the adjacency list representation, è All the vertices are stored in an array of structure containing ‘data’ and ‘link’ fields. è The linked chains represent the edges of a vertex with its neighbors. In the figure, there are 6 vertices, represented by the array of length 6, and the chains represent the edges. Below is another example: Let us first define the structure of a vertex in a graph. struct vertex { int vertexKey; struct edge *edgePtr; }vertex; The vertexKey is the data field of the vertex, and edgePtr is the edge pointer, declared next. The graph can be declared as: struct vertex graph[10]; int vertexCount=0; Here...
Comments
Post a Comment