Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab016
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab016
提交
abb026f2
提交
abb026f2
5月 21, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
5e83cca8
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
main.c
main.c
+22
-22
没有找到文件。
main.c
浏览文件 @
abb026f2
#include "Graph.h"
#include "Graph.h"
int
visited
[
MAX_VERTEX_NUM
];
//
顶点访问标志数组.0 表示未访问;大于 0 表示访问的先后次序
.
int
visited
[
MAX_VERTEX_NUM
];
//
Array of vertex access flags.0 means no access; Greater than 0 indicates the order of access
.
Queue
queue
;
//
队列
Queue
queue
;
//
The queue
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -10,23 +10,23 @@ int main(int argc, char* argv[])
...
@@ -10,23 +10,23 @@ int main(int argc, char* argv[])
int
i
,
j
;
int
i
,
j
;
//
//
//
初始化图
//
Initialize the figure
//
//
InitGraph
(
&
graph
);
InitGraph
(
&
graph
);
//
//
//
初始化队列
//
Initialization queue
//
//
InitQueue
(
&
queue
);
InitQueue
(
&
queue
);
//
//
//
初始化访问标志数组
//
Initializes an array of access flags
//
//
for
(
i
=
0
;
i
<
graph
.
length
;
i
++
)
for
(
i
=
0
;
i
<
graph
.
length
;
i
++
)
visited
[
i
]
=
0
;
visited
[
i
]
=
0
;
//
//
//
广度优先搜索
//
Breadth-first search
//
//
BreadthFirstSearch
(
&
graph
);
BreadthFirstSearch
(
&
graph
);
...
@@ -44,7 +44,7 @@ int main(int argc, char* argv[])
...
@@ -44,7 +44,7 @@ int main(int argc, char* argv[])
//
//
//
销毁图
//
Destruction of figure
//
//
DeleteGraph
(
&
graph
);
DeleteGraph
(
&
graph
);
...
@@ -53,16 +53,16 @@ int main(int argc, char* argv[])
...
@@ -53,16 +53,16 @@ int main(int argc, char* argv[])
/*
/*
function:
function:
广度优先搜索
.
Breadth-first search
.
parameter:
parameter:
pGraph --
图指针
pGraph --
Figure pointer
*/
*/
void
BreadthFirstSearch
(
Graph
*
pGraph
)
void
BreadthFirstSearch
(
Graph
*
pGraph
)
{
{
ArcNode
*
pArcNode
;
//
边(弧节点指针
ArcNode
*
pArcNode
;
//
Edge (arc) node pointer
int
i
,
v
;
//
顶点序号.从 0 开始计数
.
int
i
,
v
;
//
Vertex ordinal. Counts from 0
.
int
nVisitCount
=
0
;
//
访问计数器
.
int
nVisitCount
=
0
;
//
Access counter
.
//
//
// TODO: Add the code here
// TODO: Add the code here
...
@@ -73,14 +73,14 @@ void BreadthFirstSearch(Graph* pGraph)
...
@@ -73,14 +73,14 @@ void BreadthFirstSearch(Graph* pGraph)
/*
/*
function:
function:
使用给定的数据初始化图的邻接表
Initializes the graph's adjacency list with the given data
parameter:
parameter:
pGraph --
图指针
pGraph --
Figure pointer
*/
*/
typedef
struct
VertexArrayEntry
{
typedef
struct
VertexArrayEntry
{
const
char
*
name
;
//
顶点名称.NULL 表示顶点序列结束
.
const
char
*
name
;
//
Name of the vertices.NULL indicates the end of the vertex sequence
.
int
VexIndex
[
MAX_VERTEX_NUM
];
//
与该顶点邻接的顶点序列.-1 表示序列结束
.
int
VexIndex
[
MAX_VERTEX_NUM
];
//
The sequence of vertices adjacent to this vertex.-1 indicates the end of the sequence
.
}
VertexArrayEntry
;
}
VertexArrayEntry
;
const
VertexArrayEntry
VertexArray
[]
=
{
const
VertexArrayEntry
VertexArray
[]
=
{
{
"V0"
,
{
2
,
5
,
1
,
-
1
}
},
{
"V0"
,
{
2
,
5
,
1
,
-
1
}
},
...
@@ -90,20 +90,20 @@ const VertexArrayEntry VertexArray[] = {
...
@@ -90,20 +90,20 @@ const VertexArrayEntry VertexArray[] = {
{
"V4"
,
{
1
,
3
,
-
1
}
},
{
"V4"
,
{
1
,
3
,
-
1
}
},
{
"V5"
,
{
0
,
6
,
-
1
}
},
{
"V5"
,
{
0
,
6
,
-
1
}
},
{
"V6"
,
{
2
,
5
,
0
,
-
1
}
},
{
"V6"
,
{
2
,
5
,
0
,
-
1
}
},
{
NULL
}
//
结束标志
{
NULL
}
//
End mark
};
};
void
InitGraph
(
Graph
*
pGraph
)
void
InitGraph
(
Graph
*
pGraph
)
{
{
int
i
,
j
;
int
i
,
j
;
ArcNode
**
pArcNodePtr
;
//
指向指针的指针
ArcNode
**
pArcNodePtr
;
//
Pointer to pointer
//
//
//
重置图中的数据
//
Reset the length of the data in the graph
//
//
pGraph
->
length
=
0
;
pGraph
->
length
=
0
;
//
//
//
使用给定的数据初始化图的邻接表
//
Initializes the graph's adjacency list with the given data
//
//
for
(
i
=
0
;
i
<
MAX_VERTEX_NUM
;
i
++
)
for
(
i
=
0
;
i
<
MAX_VERTEX_NUM
;
i
++
)
{
{
...
@@ -132,10 +132,10 @@ void InitGraph(Graph* pGraph)
...
@@ -132,10 +132,10 @@ void InitGraph(Graph* pGraph)
/*
/*
function:
function:
销毁图
Destruction of figure
parameter:
parameter:
pGraph --
图指针
pGraph --
Figure pointer
*/
*/
void
DeleteGraph
(
Graph
*
pGraph
)
void
DeleteGraph
(
Graph
*
pGraph
)
{
{
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论