作业帮 > 综合 > 作业

C语言编程,求解非加权无向图(简单图)的平均路径长度

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/02 17:05:35
C语言编程,求解非加权无向图(简单图)的平均路径长度
请给出一个非加权无向图的求解其平均路径长度的程序,C语言.只是,非加权无向图要像以下的格式那样给出.
graph sample {
a -- b;
b -- c;
c -- a;
}
不需要纠结于什么叫非加权无向图,就是数据结构中的网状结构,无加权无向.
网是带权值的,上面的“网”应该是“图”,打错了
求非加权无向图的平均路径长度,C语言(像数据结构中的伪码那样就行),就这么难么...
平均路径长度:
所有点对之间的最短路径长度的算术平均值.
#include
void main()
{
const int m = 1000;
int matric[5][5] =
{
{0,1,m,1,m}, //graph sample { 0--1;0--3;1--2;2--3;2--4;3--4;}
{1,0,1,m,m}, //this is the adjacency matrix
{m,1,0,1,1}, //"0" means the same node to itself
{1,m,1,0,1}, //"1" means there's an edge between the two nodes
{m,m,1,1,0} //"m" means there's no edge between the two nodes
};
int patch[5][5]; //patch
int a[5][5]; //shortest record

int i,j,k,pre;

for (i=0; i