Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab019
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab019
提交
797bc265
提交
797bc265
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
b83e6652
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
23 行删除
+20
-23
ShortestPath.h
ShortestPath.h
+6
-12
main.c
main.c
+14
-11
没有找到文件。
ShortestPath.h
浏览文件 @
797bc265
#ifndef SHORTESTPATH_H_
#ifndef SHORTESTPATH_H_
#define SHORTESTPATH_H_
#define SHORTESTPATH_H_
//
//
// 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
// Denotes the direct connection between two vertices, denoted by MAX in the adjacency matrix
#define MAX 100000000
#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
ShortestPath
{
typedef
struct
ShortestPath
{
int
length
;
// Shortest path length
int
length
;
// Shortest path length
int
prevex
;
// The leading vertex of Vi on the shortest path from Vo to Vi
int
prevex
;
// The leading vertex of Vi on the shortest path from Vo to Vi
}
ShortestPath
;
}
ShortestPath
;
//
//
// Declare functions
// Declare functions
//
//
void
Dijkstra
(
GraphMatrix
*
pGraph
);
void
Dijkstra
(
GraphMatrix
*
pGraph
);
void
OutputResult
(
GraphMatrix
*
pGraph
);
void
OutputResult
(
GraphMatrix
*
pGraph
);
//
//
// Declare global variables here
// Declare global variables here
//
//
extern
ShortestPath
dist
[
MAX
];
extern
ShortestPath
dist
[
MAX
];
#endif
/* SHORTESTPATH_H_ */
#endif
/* SHORTESTPATH_H_ */
main.c
浏览文件 @
797bc265
...
@@ -8,14 +8,17 @@ int main(int argc, char* argv[])
...
@@ -8,14 +8,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
},
{
{
MAX
,
0
,
15
,
MAX
,
5
,
MAX
},
{
{
20
,
100
,
0
,
15
,
MAX
,
MAX
},
{
0
,
50
,
10
,
MAX
,
45
,
MAX
},
{
MAX
,
20
,
MAX
,
0
,
35
,
MAX
},
{
MAX
,
0
,
15
,
MAX
,
5
,
MAX
},
{
MAX
,
MAX
,
MAX
,
30
,
0
,
MAX
},
{
20
,
100
,
0
,
15
,
MAX
,
MAX
},
{
MAX
,
MAX
,
MAX
,
3
,
MAX
,
0
}
{
MAX
,
20
,
MAX
,
0
,
35
,
MAX
},
}};
{
MAX
,
MAX
,
MAX
,
30
,
0
,
MAX
},
{
MAX
,
MAX
,
MAX
,
3
,
MAX
,
0
}
}
};
//
//
//Shortest path (Dijkstra algorithm)
//Shortest path (Dijkstra algorithm)
...
@@ -60,15 +63,15 @@ void OutputResult(GraphMatrix* pGraph)
...
@@ -60,15 +63,15 @@ void OutputResult(GraphMatrix* pGraph)
int
i
;
int
i
;
printf
(
"ShortestPath: "
);
printf
(
"ShortestPath: "
);
for
(
i
=
0
;
i
<
VERTEXNUM
;
i
++
)
for
(
i
=
0
;
i
<
VERTEXNUM
;
i
++
)
{
{
if
(
pGraph
->
Arcs
[
i
][
i
]
==
1
)
if
(
pGraph
->
Arcs
[
i
][
i
]
==
1
)
{
{
printf
(
"[%3d, %2d]"
,
dist
[
i
].
length
,
dist
[
i
].
prevex
);
printf
(
"[%3d, %2d]"
,
dist
[
i
].
length
,
dist
[
i
].
prevex
);
}
}
else
else
{
{
if
(
dist
[
i
].
length
==
MAX
)
if
(
dist
[
i
].
length
==
MAX
)
{
{
printf
(
"(%3s, %2d)"
,
"MAX"
,
dist
[
i
].
prevex
);
printf
(
"(%3s, %2d)"
,
"MAX"
,
dist
[
i
].
prevex
);
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论