创建邻接矩阵和邻接链表

来源:互联网 发布:底部反转形态 知乎 编辑:程序博客网 时间:2024/06/04 19:50
//***************创建邻接矩阵*************#define  INFINITY INT_MAX //最大值无穷大#define MAX_VERTEX_NUM 20//假设存储的最大顶点数typedef enum{DG,DN,AG,AN} GraphKind;typedef struct ArcCell //弧结点的定义{VRType adj; //边InfoType *info;//入度}ArcCell, AdjMatrix[MAX_VERTEX_NUM];//用这个数组来存储这个图typedef strucr{//对图的定义VertexType vexs[MAX_VERTEX_NUM];//数组用来存储所有图的顶点AdjMatrix arcs;//邻接矩阵int Vernum, arcnum;//顶点的总数 ,弧的总数GraphKind kind;//图的种类标志}
//***************创建邻接表*************typedef struct ArcNode //邻接表中的表结点{int adjvex;//邻接点域,存放于Vi邻接的点在表头数组中的位置struct ArcNode *nextarc;//链域,指示下一条边int weight;//权重}ArcNode ;//头结点typedef struct VNode{vertex data;//存放顶点信息ArcNode *firstarc;//指向第一个邻接点}Vnode, AdjList[MAX_VERTEX_NUM];typedef struct{AdjList vertices;//表头向量int vernum, arcnum;//存放顶点数和边的数目int kind;//图的种类标志}ALGraph;
等以后研究透彻了再写一篇详细的讲解。