提交 123916fc 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 fead5194
......@@ -6,51 +6,46 @@
// Include the C standard library header file here
//
#include <stdio.h>
//
// Other header files are included here
//
//
// Define the data structure here
//
#define MAX 100000000 // Denotes the direct connection between two vertices, denoted by MAX in the adjacency matrix
#define MAX 100000000 // Denotes the direct connection between two vertices,
// denoted by MAX in the adjacency matrix
#define VERTEXNUM 6 // Vertex number
typedef struct GraphMatrix{
typedef struct GraphMatrix
{
int Arcs[VERTEXNUM][VERTEXNUM]; // Edge information
}GraphMatrix;
typedef struct ShortPath{
int a[VERTEXNUM][VERTEXNUM]; // Store the shortest path length between each pair of vertices
int nextvex[VERTEXNUM][VERTEXNUM]; // The subscript of Vi's subsequent vertices on the shortest path from Vi to Vj
typedef struct ShortPath
{
// Store the shortest path length between each pair of vertices
int a[VERTEXNUM][VERTEXNUM];
// The subscript of Vi's subsequent vertices on the shortest path from Vi to Vj
int nextvex[VERTEXNUM][VERTEXNUM];
}ShortPath;
//
// Declare the function here
//
void Floyd(GraphMatrix* pGraph, ShortPath* pPath);
void OutputResult(ShortPath* pPath);
//
// Declare global variables here
//
extern ShortPath SPath;
#endif /* SHORTESTPATH_H_ */
......@@ -7,14 +7,17 @@ int main(int argc, char* argv[])
//
// Initialization graph (adjacency matrix representation of graph)
//
GraphMatrix Graph = {{
{ 0, 50, 10, MAX, 45, MAX},
{ MAX, 0, 15, MAX, 5, MAX},
{ 20, MAX, 0, 15, MAX, MAX},
{ MAX, 20, MAX, 0, 35, MAX},
{ MAX, MAX, MAX, 30, 0, MAX},
{ MAX, MAX, MAX, 3, MAX, 0}
}};
GraphMatrix Graph =
{
{
{ 0, 50, 10, MAX, 45, MAX},
{ MAX, 0, 15, MAX, 5, MAX},
{ 20, MAX, 0, 15, MAX, MAX},
{ MAX, 20, MAX, 0, 35, MAX},
{ MAX, MAX, MAX, 30, 0, MAX},
{ MAX, MAX, MAX, 3, MAX, 0}
}
};
//
// Shortest path (Floyd algorithm)
......@@ -59,9 +62,9 @@ void OutputResult(ShortPath* pPath)
int i, j;
printf("Subsequent vertex index array:\n");
for(i = 0; i < VERTEXNUM; i++)
for (i = 0; i < VERTEXNUM; i++)
{
for(j = 0; j < VERTEXNUM; j++)
for (j = 0; j < VERTEXNUM; j++)
{
printf("%d ", pPath->nextvex[i][j]);
}
......@@ -69,11 +72,11 @@ void OutputResult(ShortPath* pPath)
}
printf("An array of shortest path lengths between vertices:\n");
for(i = 0; i < VERTEXNUM; i++)
for (i = 0; i < VERTEXNUM; i++)
{
for(j = 0; j < VERTEXNUM; j++)
for (j = 0; j < VERTEXNUM; j++)
{
if(pPath->a[i][j] == MAX)
if (pPath->a[i][j] == MAX)
{
printf("MAX ");
}
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论