Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab017
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab017
提交
33c2d850
提交
33c2d850
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
cc40ac6c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
40 行增加
和
38 行删除
+40
-38
Stack.c
Stack.c
+6
-2
Stack.h
Stack.h
+4
-12
TopologicalSort.h
TopologicalSort.h
+8
-9
main.c
main.c
+22
-15
没有找到文件。
Stack.c
浏览文件 @
33c2d850
...
...
@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem)
//
// Stack full, push failed.
//
if
(
MAX_STACK_LENGTH
-
1
<
pS
->
top
)
if
(
MAX_STACK_LENGTH
-
1
<
pS
->
top
)
{
return
-
1
;
}
pS
->
top
++
;
pS
->
buffer
[
pS
->
top
]
=
Elem
;
// Insert the element at the top of the stack
...
...
@@ -56,8 +58,10 @@ int Pop(Stack* pS)
//
// The stack is empty and the pop fails
//
if
(
StackEmpty
(
pS
))
if
(
StackEmpty
(
pS
))
{
return
-
1
;
}
Elem
=
pS
->
buffer
[
pS
->
top
];
pS
->
top
--
;
...
...
Stack.h
浏览文件 @
33c2d850
#ifndef STACK_H_
#define STACK_H_
//
// Include the C standard library header file here
//
//
// Other header files are included here
//
//
// Define the data structure here
//
...
...
@@ -21,12 +16,13 @@
#define MAX_STACK_LENGTH 64 // Maximum length of stack
// Stack
typedef
struct
Stack
{
typedef
struct
Stack
{
int
buffer
[
MAX_STACK_LENGTH
];
// Stack buffer
int
top
;
// Indicates the position at the top of the stack, not the number of elements in the stack
// Indicates the position at the top of the stack, not the number of elements in the stack
int
top
;
}
Stack
;
//
// Declare the function here
//
...
...
@@ -36,12 +32,8 @@ int Push(Stack* pS, int Elem);
int
Pop
(
Stack
*
pS
);
int
StackEmpty
(
Stack
*
pS
);
//
// Declare global variables here
//
#endif
/* STACK_H_ */
TopologicalSort.h
浏览文件 @
33c2d850
#ifndef TOPOLOGICALSORT_H_
#define TOPOLOGICALSORT_H_
//
// Include the C standard library header file here
//
#include <stdio.h>
//
// Other header files are included here
//
#include "Stack.h"
//
// Define the data structure here
//
...
...
@@ -24,25 +20,28 @@
#define MAX_VERTEX_NUM 50 // Maximum number of vertices
// Edge (arc)
typedef
struct
EdgeNode
{
typedef
struct
EdgeNode
{
int
vertex
;
// Vertex field. That is, the index of the vertex in the vertex array.
struct
EdgeNode
*
nextedge
;
// Chain domain. Point to the next Edge (arc).
}
EdgeNode
,
*
PEdgeList
;
// vertex
typedef
struct
VexNode
{
const
char
*
name
;
// Use a string as the vertex's stored value. You can also think of it as the vertex's name.
typedef
struct
VexNode
{
// Use a string as the vertex's stored value. You can also think of it as the vertex's name.
const
char
*
name
;
PEdgeList
firstarc
;
// Pointing to the first side arc.
int
Indegree
;
// indegree of vertex.
}
VexNode
;
// Graph. Use adjacency list storage
typedef
struct
GraphList
{
typedef
struct
GraphList
{
VexNode
vexlist
[
MAX_VERTEX_NUM
];
// Vertex table
int
length
;
// Vertex number
}
GraphList
;
//
// Declare the function here
//
...
...
main.c
浏览文件 @
33c2d850
#include "TopologicalSort.h"
#include <stdlib.h>
Stack
stack
;
...
...
@@ -82,11 +83,14 @@ function:
parameter:
pGraphList -- Figure pointer
*/
typedef
struct
VertexArrayEntry
{
typedef
struct
VertexArrayEntry
{
const
char
*
name
;
// Name of the vertices.NULL indicates the end of the vertex sequence.
int
VexIndex
[
MAX_VERTEX_NUM
];
// The sequence of vertices adjacent to this vertex.-1 indicates the end of the sequence.
// The sequence of vertices adjacent to this vertex.-1 indicates the end of the sequence.
int
VexIndex
[
MAX_VERTEX_NUM
];
}
VertexArrayEntry
;
const
VertexArrayEntry
VertexArray
[]
=
{
const
VertexArrayEntry
VertexArray
[]
=
{
{
"C1"
,
{
2
,
1
,
3
,
11
,
-
1
}},
{
"C2"
,
{
2
,
-
1
}
},
{
"C3"
,
{
7
,
6
,
4
,
-
1
}
},
...
...
@@ -96,15 +100,14 @@ const VertexArrayEntry VertexArray[] = {
{
"C7"
,
{
-
1
}
},
{
"C8"
,
{
-
1
}
},
{
"C9"
,
{
10
,
11
,
9
,
-
1
}
},
{
"C10"
,{
11
,
-
1
}
},
{
"C11"
,
{
5
,
-
1
}
},
{
"C12"
,{
-
1
}
},
{
"C10"
,
{
11
,
-
1
}
},
{
"C11"
,
{
5
,
-
1
}
},
{
"C12"
,
{
-
1
}
},
{
NULL
}
// End mark
};
void
InitGraph
(
GraphList
*
pGraphList
)
{
int
i
,
j
;
// The cursor
EdgeNode
**
pEdgeNodePtr
;
// Pointer to a pointer to an edge (arc) node pointer
//
...
...
@@ -115,17 +118,21 @@ void InitGraph(GraphList* pGraphList)
//
// Initializes the graph's adjacency list with the given data
//
for
(
i
=
0
;
i
<
MAX_VERTEX_NUM
;
i
++
)
for
(
int
i
=
0
;
i
<
MAX_VERTEX_NUM
;
i
++
)
{
if
(
NULL
==
VertexArray
[
i
].
name
)
// Name of the vertices.NULL indicates the end of the vertex sequence.
// Name of the vertices.NULL indicates the end of the vertex sequence.
if
(
NULL
==
VertexArray
[
i
].
name
)
{
break
;
}
pGraphList
->
vexlist
[
i
].
name
=
VertexArray
[
i
].
name
;
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
// Pointer to vertex array (where pointer is initialized)
for
(
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
// Pointer to vertex array (where pointer is initialized)
pEdgeNodePtr
=
&
pGraphList
->
vexlist
[
i
].
firstarc
;
for
(
int
j
=
0
;
j
<
MAX_VERTEX_NUM
;
j
++
)
{
if
(
-
1
==
VertexArray
[
i
].
VexIndex
[
j
])
if
(
-
1
==
VertexArray
[
i
].
VexIndex
[
j
])
{
*
pEdgeNodePtr
=
NULL
;
break
;
...
...
@@ -152,9 +159,9 @@ void DeleteGraph(GraphList* pGraphList)
int
i
;
EdgeNode
*
pEdgeNode
;
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
for
(
i
=
0
;
i
<
pGraphList
->
length
;
i
++
)
{
while
(
pGraphList
->
vexlist
[
i
].
firstarc
!=
NULL
)
while
(
pGraphList
->
vexlist
[
i
].
firstarc
!=
NULL
)
{
pEdgeNode
=
pGraphList
->
vexlist
[
i
].
firstarc
;
pGraphList
->
vexlist
[
i
].
firstarc
=
pEdgeNode
->
nextedge
;
...
...
@@ -168,7 +175,7 @@ void DeleteGraph(GraphList* pGraphList)
void
OutputSortResult
(
GraphList
*
pGraphList
)
{
int
i
;
for
(
i
=
0
;
i
<
ResultLength
;
i
++
)
for
(
i
=
0
;
i
<
ResultLength
;
i
++
)
{
printf
(
"%d "
,
TopoSortResult
[
i
]);
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论