Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab017
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab017
提交
8efe800c
提交
8efe800c
5月 21, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
51155969
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
24 行删除
+24
-24
main.c
main.c
+24
-24
没有找到文件。
main.c
浏览文件 @
8efe800c
...
@@ -4,11 +4,11 @@ Stack stack;
...
@@ -4,11 +4,11 @@ Stack stack;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
GraphList
Graphlist
;
//
用于拓扑排序的图
GraphList
Graphlist
;
//
A graph used for topological sorting
int
i
;
int
i
;
//
//
//
初始化图
//
Initialize the figure
//
//
InitGraph
(
&
Graphlist
);
InitGraph
(
&
Graphlist
);
...
@@ -18,14 +18,14 @@ int main(int argc, char* argv[])
...
@@ -18,14 +18,14 @@ int main(int argc, char* argv[])
InitStack
(
&
stack
);
InitStack
(
&
stack
);
//
//
//
拓扑排序
//
Topological sort
//
//
TopoSort
(
&
Graphlist
);
TopoSort
(
&
Graphlist
);
OutputSortResult
(
&
Graphlist
);
OutputSortResult
(
&
Graphlist
);
//
//
//
销毁图
//
Destruction of figure
//
//
DeleteGraph
(
&
Graphlist
);
DeleteGraph
(
&
Graphlist
);
...
@@ -34,10 +34,10 @@ int main(int argc, char* argv[])
...
@@ -34,10 +34,10 @@ int main(int argc, char* argv[])
/*
/*
function:
function:
求图中所有顶点的入度
Find the degree of entry of all vertices in the graph
parameter:
parameter:
pGraphList --
图指针
pGraphList --
Figure pointer
*/
*/
void
FindInDegree
(
GraphList
*
pGraphList
)
void
FindInDegree
(
GraphList
*
pGraphList
)
...
@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList)
...
@@ -51,20 +51,20 @@ void FindInDegree(GraphList *pGraphList)
/*
/*
function:
function:
拓扑排序
Topological sort
parameter:
parameter:
pGraphList --
图指针
pGraphList --
Figure pointer
returned value:
returned value:
如果排序成功返回 1
Returns 1 if the sort succeeds
如果排序失败返回 0
Returns 1 if the sort fails
*/
*/
int
TopoSortResult
[
MAX_VERTEX_NUM
];
//
存储排序结果(下标)的数组
int
TopoSortResult
[
MAX_VERTEX_NUM
];
//
An array that stores sorted results (subscripts)
int
ResultLength
=
0
;
// The length of the array that stores the sorted result (subscript)
int
ResultLength
=
0
;
// The length of the array that stores the sorted result (subscript)
int
TopoSort
(
GraphList
*
pGraphList
)
int
TopoSort
(
GraphList
*
pGraphList
)
{
{
EdgeNode
*
pEdgeNode
;
//
边(弧节点指针
EdgeNode
*
pEdgeNode
;
//
Edge (arc) node pointer
int
i
,
k
;
// The cursor
int
i
,
k
;
// The cursor
//
//
...
@@ -77,14 +77,14 @@ int TopoSort(GraphList *pGraphList)
...
@@ -77,14 +77,14 @@ int TopoSort(GraphList *pGraphList)
/*
/*
function:
function:
使用给定的数据初始化图的邻接表
Initializes the graph's adjacency list with the given data
parameter:
parameter:
pGraphList --
图指针
pGraphList --
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
[]
=
{
{
"C1"
,
{
2
,
1
,
3
,
11
,
-
1
}},
{
"C1"
,
{
2
,
1
,
3
,
11
,
-
1
}},
...
@@ -99,30 +99,30 @@ const VertexArrayEntry VertexArray[] = {
...
@@ -99,30 +99,30 @@ const VertexArrayEntry VertexArray[] = {
{
"C10"
,{
11
,
-
1
}
},
{
"C10"
,{
11
,
-
1
}
},
{
"C11"
,{
5
,
-
1
}
},
{
"C11"
,{
5
,
-
1
}
},
{
"C12"
,{
-
1
}
},
{
"C12"
,{
-
1
}
},
{
NULL
}
//
结束标志
{
NULL
}
//
End mark
};
};
void
InitGraph
(
GraphList
*
pGraphList
)
void
InitGraph
(
GraphList
*
pGraphList
)
{
{
int
i
,
j
;
// The cursor
int
i
,
j
;
// The cursor
EdgeNode
**
pEdgeNodePtr
;
//
指向边(弧节点指针的指针
EdgeNode
**
pEdgeNodePtr
;
//
Pointer to a pointer to an edge (arc) node pointer
//
//
//
重置图中的数据 lengt
h
//
Reset the length of the data in the grap
h
//
//
pGraphList
->
length
=
0
;
pGraphList
->
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
++
)
{
{
if
(
NULL
==
VertexArray
[
i
].
name
)
//
顶点名称.NULL表示顶点序列结束
.
if
(
NULL
==
VertexArray
[
i
].
name
)
//
Name of the vertices.NULL indicates the end of the vertex sequence
.
break
;
break
;
pGraphList
->
vexlist
[
i
].
name
=
VertexArray
[
i
].
name
;
pGraphList
->
vexlist
[
i
].
name
=
VertexArray
[
i
].
name
;
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
//
使指针指向顶点数组(初始化指针的位置
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
//
Pointer to vertex array (where pointer is initialized)
for
(
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
for
(
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
{
{
if
(
-
1
==
VertexArray
[
i
].
VexIndex
[
j
])
if
(
-
1
==
VertexArray
[
i
].
VexIndex
[
j
])
...
@@ -142,10 +142,10 @@ void InitGraph(GraphList* pGraphList)
...
@@ -142,10 +142,10 @@ void InitGraph(GraphList* pGraphList)
/*
/*
function:
function:
销毁图
Destruction of figure
parameter:
parameter:
pGraphList --
图指针
pGraphList --
Figure pointer
*/
*/
void
DeleteGraph
(
GraphList
*
pGraphList
)
void
DeleteGraph
(
GraphList
*
pGraphList
)
{
{
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论