41 graph storage-adjacency list method

Adjacent table method: When a graph is a sparse graph, using adjacency matrix notation obviously wastes a lot of storage space. The graph's adjacency list method combines sequential storage and chain storage, which greatly reduces this unnecessary waste.
Insert picture description here

The storage structure of the graph adjacency table is defined as follows:
#define MaxVertexNum 100 //Maximum number of vertices in the graph
Typedef struct ArcNode{ //edge table node
Int adjvex; //The position of the vertex pointed to by the arc
Struct ArcNode *next; //Pointer to the next arc
//infoType info; //The edge weight of the network
}ArcNode;
Typedef struct VNode{ //
VertexType data; //Vertex information
ArcNode *first; //Point to the first The pointer of the arc attached to the vertex
}VNode,AdiList[MaxVertexNum];
Typedef struct{ AdjList vertices; //Adjacency list Int vexnum,arcnum; //The number of vertices and arcs of the graph }ALGraph; //ALGraph is stored as an adjacency list Graph type



Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_41883890/article/details/113026263