RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
邻接矩阵表示有向带权图
#include 
#include 
#include 

typedef char VertexType[5]; //存储顶点值


#define MaxSize 50
#define INIT 10000

typedef struct //邻接矩阵,存储弧的信息
{
    int adj;
}ArcNode,AdjMatrix[MaxSize][MaxSize];

typedef struct   //图的类型定义
{
    VertexType vex[MaxSize];  //存储顶点值
    AdjMatrix arc;  //邻接矩阵
    int arcnum,vexnum;   //前者弧数,后者顶点数
}MGraph;

void CreateVertex(MGraph *G)    //创建邻接矩阵
{
    int i,j,k,w;  
    VertexType v1,v2;
    
    printf("请输入有向带权图的顶点数和弧数:(空格间隔)\n");
    scanf("%d%d",&(*G).vexnum,&(*G).arcnum);
    
    printf("请输入%d个顶点的值:\n",G->vexnum);
    for ( i=0 ; ivexnum ; i++ )
    {
        scanf("%s",&G->vex[i]);
    }
    
    for ( i=0 ; ivexnum ; i++ )     //初始化邻接矩阵
    {
        for ( j=0 ; jvexnum ; j++ )
        {
            G->arc[i][j].adj = INIT;
        }
    }
    
    printf("请输入%d条弧的弧尾,弧头和权值:\n",G->arcnum);
    for ( k=0 ; karcnum ; k++ )
    {
        scanf("%s%s%d",v1,v2,&w);
        i = LocateVertex(*G,v1);
        j = LocateVertex(*G,v2);
        
        G->arc[i][j].adj = w;
    }
}


int LocateVertex(MGraph G,VertexType v)  //索引
{
    int i;
    
    for ( i=0 ; i            
            
                                                            
分享题目:邻接矩阵表示有向带权图
转载源于:http://cqwzjz.cn/article/pgshoj.html