Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab020
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab020
提交
123916fc
提交
123916fc
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
fead5194
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
22 行删除
+20
-22
ShortestPath.h
ShortestPath.h
+10
-15
main.c
main.c
+10
-7
没有找到文件。
ShortestPath.h
浏览文件 @
123916fc
...
@@ -6,51 +6,46 @@
...
@@ -6,51 +6,46 @@
// Include the C standard library header file here
// Include the C standard library header file here
//
//
#include <stdio.h>
#include <stdio.h>
//
//
// Other header files are included here
// Other header files are included here
//
//
//
//
// Define the data structure 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
#define VERTEXNUM 6 // Vertex number
typedef
struct
GraphMatrix
{
typedef
struct
GraphMatrix
{
int
Arcs
[
VERTEXNUM
][
VERTEXNUM
];
// Edge information
int
Arcs
[
VERTEXNUM
][
VERTEXNUM
];
// Edge information
}
GraphMatrix
;
}
GraphMatrix
;
typedef
struct
ShortPath
{
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
// 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
;
}
ShortPath
;
//
//
// Declare the function here
// Declare the function here
//
//
void
Floyd
(
GraphMatrix
*
pGraph
,
ShortPath
*
pPath
);
void
Floyd
(
GraphMatrix
*
pGraph
,
ShortPath
*
pPath
);
void
OutputResult
(
ShortPath
*
pPath
);
void
OutputResult
(
ShortPath
*
pPath
);
//
//
// Declare global variables here
// Declare global variables here
//
//
extern
ShortPath
SPath
;
extern
ShortPath
SPath
;
#endif
/* SHORTESTPATH_H_ */
#endif
/* SHORTESTPATH_H_ */
main.c
浏览文件 @
123916fc
...
@@ -7,14 +7,17 @@ int main(int argc, char* argv[])
...
@@ -7,14 +7,17 @@ int main(int argc, char* argv[])
//
//
// Initialization graph (adjacency matrix representation of graph)
// Initialization graph (adjacency matrix representation of graph)
//
//
GraphMatrix
Graph
=
{{
GraphMatrix
Graph
=
{
{
{
0
,
50
,
10
,
MAX
,
45
,
MAX
},
{
0
,
50
,
10
,
MAX
,
45
,
MAX
},
{
MAX
,
0
,
15
,
MAX
,
5
,
MAX
},
{
MAX
,
0
,
15
,
MAX
,
5
,
MAX
},
{
20
,
MAX
,
0
,
15
,
MAX
,
MAX
},
{
20
,
MAX
,
0
,
15
,
MAX
,
MAX
},
{
MAX
,
20
,
MAX
,
0
,
35
,
MAX
},
{
MAX
,
20
,
MAX
,
0
,
35
,
MAX
},
{
MAX
,
MAX
,
MAX
,
30
,
0
,
MAX
},
{
MAX
,
MAX
,
MAX
,
30
,
0
,
MAX
},
{
MAX
,
MAX
,
MAX
,
3
,
MAX
,
0
}
{
MAX
,
MAX
,
MAX
,
3
,
MAX
,
0
}
}};
}
};
//
//
// Shortest path (Floyd algorithm)
// Shortest path (Floyd algorithm)
...
@@ -59,9 +62,9 @@ void OutputResult(ShortPath* pPath)
...
@@ -59,9 +62,9 @@ void OutputResult(ShortPath* pPath)
int
i
,
j
;
int
i
,
j
;
printf
(
"Subsequent vertex index array:
\n
"
);
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
]);
printf
(
"%d "
,
pPath
->
nextvex
[
i
][
j
]);
}
}
...
@@ -69,11 +72,11 @@ void OutputResult(ShortPath* pPath)
...
@@ -69,11 +72,11 @@ void OutputResult(ShortPath* pPath)
}
}
printf
(
"An array of shortest path lengths between vertices:
\n
"
);
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 "
);
printf
(
"MAX "
);
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论