2007-08-23
floyd最短路径算法的实现方法 - [Algorithms]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://conoon.blogbus.com/logs/7872491.html
floyd最短路径算法的实现方法很多人可能还不清除,看了下面这段代码你应该能基本了解floyd最短路径算法了
#include
#include
#include
#include
#define MAX_NAME 20
#define MAX_INFO 200
typedef int VRType;
typedef char VertexType[MAX_NAME];
#define INFINITY 65535
#define MAX_VERTEX_NUM 50
typedef struct
{
VRType adj;
}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
struct MGraph
{
VertexType vexs[MAX_VERTEX_NUM];
AdjMatrix arcs;
int vexnum;
int arcnum;
};
typedef int DistancMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
//返回顶点在图中的序号
int LocateVex(MGraph G,VertexType u)
{
int i;
for(i =0; i< G.vexnum;i++)
{
if(strcmp(u,G.vexs[i]) == 0)
return i;
}
return -1;
}
//read the file for creating the MGraph
int CreateDN(MGraph &G)
{
FILE *fp;
char start_city_name[MAX_NAME];
char end_city_name[MAX_NAME];
int distance_of_city = 0;
fp=fopen("./ukcities.txt","r");
//init MGraph data
//顶点数量
G.vexnum = 0;
//初始化两点之间的弧长信息,在这里即为两个城市间的距离
//INFINITY在这里应当理解为无穷大的意思,65535只是一个参考值
for(int p=0;p
随机文章: