图的邻接矩阵表示及创建

来源:互联网 发布:yunos删除预装软件 编辑:程序博客网 时间:2024/06/06 02:26
#include<cstdio>#define MaxInt 32767#define MaxVexNum 100#define Status int#define OK 1typedef char VerTexType;//假设定点的数据类型是字符型typedef int ArcType;//假设边的权值为整型typedef struct{    VerTexType vexs[MaxVexNum];//顶点表    ArcType arcs[MaxVexNum][MaxVexNum];//邻接矩阵    int vexnum;//图的当前点数    int arcnum;//图的当前边数} AMGraph;//邻接矩阵的初始化Status CreateUDN(AMGraph &G){    scanf("%d%d",&G.vexnum,&G.arcnum);//输入顶点数,边数    int i,j;    for(i=0; i<G.vexnum; ++i)        scanf("%d",&G.vexs[i]);//依次输入点    for(i=0; i<G.vexnum; ++i)        for(j=0; j<G.vexnum; ++j)            G.arcs[i][j]=MaxInt;    int v1,v2,w;    for(i=0; i<G.arcnum; ++i)    {        scanf("%d%d%d",&v1,&v2,&w);//顶点与顶点相连,w代表权值        G.arcs[v1][v2]=G.arcs[v2][v1]=w;    }    return OK;}


原创粉丝点击