Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab017
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab017
提交
51155969
提交
51155969
5月 20, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
f0ef20eb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
50 行删除
+50
-50
Stack.c
Stack.c
+29
-29
main.c
main.c
+21
-21
没有找到文件。
Stack.c
浏览文件 @
51155969
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
/*
/*
功能:
function:
初始化栈。
Initialize the stack.
参数:
parameter:
pS --
栈的指针
pS --
The stack pointer
*/
*/
void
InitStack
(
Stack
*
pS
)
void
InitStack
(
Stack
*
pS
)
{
{
...
@@ -14,47 +14,47 @@ void InitStack(Stack* pS)
...
@@ -14,47 +14,47 @@ void InitStack(Stack* pS)
}
}
/*
/*
功能:
function:
将元素入栈。
Push elements on the stack.
参数:
parameter:
pS --
栈的指针
pS --
The stack pointer
Elem --
入栈的元素
Elem --
Pushed elements
返回值:
returned value:
如果插入成功返回入栈元素的值。
Returns the value of the pushed element if the insert succeeds.
如果插入失败返回 -1。
Returns -1 if insert fails.
*/
*/
int
Push
(
Stack
*
pS
,
int
Elem
)
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
;
return
-
1
;
pS
->
top
++
;
pS
->
top
++
;
pS
->
buffer
[
pS
->
top
]
=
Elem
;
//
将元素插入栈顶
pS
->
buffer
[
pS
->
top
]
=
Elem
;
//
Insert the element at the top of the stack
return
Elem
;
return
Elem
;
}
}
/*
/*
功能:
function:
将栈顶元素出栈
Pop the top element of the stack
参数:
parameter:
pS --
栈的指针
pS --
The stack pointer
返回值:
returned value:
如果出栈成功返回出栈元素的值。
If the pop succeeds, the value of the pop element is returned.
如果出栈失败返回 -1。
Returns -1 if pop fails.
*/
*/
int
Pop
(
Stack
*
pS
)
int
Pop
(
Stack
*
pS
)
{
{
int
Elem
;
int
Elem
;
//
//
//
栈为空,出栈失败
//
The stack is empty and the pop fails
//
//
if
(
StackEmpty
(
pS
))
if
(
StackEmpty
(
pS
))
return
-
1
;
return
-
1
;
...
@@ -66,15 +66,15 @@ int Pop(Stack* pS)
...
@@ -66,15 +66,15 @@ int Pop(Stack* pS)
}
}
/*
/*
功能:
function:
判断栈是否为空。
Determines whether the stack is empty.
参数:
parameter:
pQ --
栈的指针
pQ --
The stack pointer
返回值:
returned value:
如果栈空返回 1(真)
Returns 1 if stack is empty.
如果栈非空返回 0(假)
Returns 0 if the stack is not empty.
*/
*/
int
StackEmpty
(
Stack
*
pS
)
int
StackEmpty
(
Stack
*
pS
)
{
{
...
...
main.c
浏览文件 @
51155969
...
@@ -13,7 +13,7 @@ int main(int argc, char* argv[])
...
@@ -13,7 +13,7 @@ int main(int argc, char* argv[])
InitGraph
(
&
Graphlist
);
InitGraph
(
&
Graphlist
);
//
//
//
调用 InitStack 函数初始化栈
//
Call the InitStack function to initialize the stack
//
//
InitStack
(
&
stack
);
InitStack
(
&
stack
);
...
@@ -33,10 +33,10 @@ int main(int argc, char* argv[])
...
@@ -33,10 +33,10 @@ int main(int argc, char* argv[])
}
}
/*
/*
功能:
function:
求图中所有顶点的入度
求图中所有顶点的入度
参数:
parameter:
pGraphList -- 图指针
pGraphList -- 图指针
*/
*/
...
@@ -44,31 +44,31 @@ void FindInDegree(GraphList *pGraphList)
...
@@ -44,31 +44,31 @@ void FindInDegree(GraphList *pGraphList)
{
{
//
//
// TODO:
在此添加代码
// TODO:
Add the code here
//
//
}
}
/*
/*
功能:
function:
拓扑排序
拓扑排序
参数:
parameter:
pGraphList -- 图指针
pGraphList -- 图指针
返回值:
returned value:
如果排序成功返回 1
如果排序成功返回 1
如果排序失败返回 0
如果排序失败返回 0
*/
*/
int
TopoSortResult
[
MAX_VERTEX_NUM
];
// 存储排序结果(下标)的数组
int
TopoSortResult
[
MAX_VERTEX_NUM
];
// 存储排序结果(下标)的数组
int
ResultLength
=
0
;
//
存储排序结果(下标)的数组的长度
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
;
// 边(弧节点指针
int
i
,
k
;
//
游标
int
i
,
k
;
//
The cursor
//
//
// TODO:
在此添加代码
// TODO:
Add the code here
//
//
return
0
;
return
0
;
...
@@ -76,15 +76,15 @@ int TopoSort(GraphList *pGraphList)
...
@@ -76,15 +76,15 @@ int TopoSort(GraphList *pGraphList)
/*
/*
功能:
function:
使用给定的数据初始化图的邻接表
使用给定的数据初始化图的邻接表
参数:
parameter:
pGraphList -- 图指针
pGraphList -- 图指针
*/
*/
typedef
struct
VertexArrayEntry
{
typedef
struct
VertexArrayEntry
{
const
char
*
name
;
// 顶点名称
。NULL 表示顶点序列结束。
const
char
*
name
;
// 顶点名称
.NULL 表示顶点序列结束.
int
VexIndex
[
MAX_VERTEX_NUM
];
// 与该顶点邻接的顶点序列
。-1 表示序列结束。
int
VexIndex
[
MAX_VERTEX_NUM
];
// 与该顶点邻接的顶点序列
.-1 表示序列结束.
}
VertexArrayEntry
;
}
VertexArrayEntry
;
const
VertexArrayEntry
VertexArray
[]
=
{
const
VertexArrayEntry
VertexArray
[]
=
{
{
"C1"
,
{
2
,
1
,
3
,
11
,
-
1
}},
{
"C1"
,
{
2
,
1
,
3
,
11
,
-
1
}},
...
@@ -104,8 +104,8 @@ const VertexArrayEntry VertexArray[] = {
...
@@ -104,8 +104,8 @@ const VertexArrayEntry VertexArray[] = {
void
InitGraph
(
GraphList
*
pGraphList
)
void
InitGraph
(
GraphList
*
pGraphList
)
{
{
int
i
,
j
;
//
游标
int
i
,
j
;
//
The cursor
EdgeNode
**
pEdgeNodePtr
;
// 指向边(弧
)
节点指针的指针
EdgeNode
**
pEdgeNodePtr
;
// 指向边(弧节点指针的指针
//
//
// 重置图中的数据 length
// 重置图中的数据 length
...
@@ -117,12 +117,12 @@ void InitGraph(GraphList* pGraphList)
...
@@ -117,12 +117,12 @@ void InitGraph(GraphList* pGraphList)
//
//
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
)
// 顶点名称
.NULL表示顶点序列结束.
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
;
// 使指针指向顶点数组(初始化指针的位置
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
])
...
@@ -141,10 +141,10 @@ void InitGraph(GraphList* pGraphList)
...
@@ -141,10 +141,10 @@ void InitGraph(GraphList* pGraphList)
}
}
/*
/*
功能:
function:
销毁图
销毁图
参数:
parameter:
pGraphList -- 图指针
pGraphList -- 图指针
*/
*/
void
DeleteGraph
(
GraphList
*
pGraphList
)
void
DeleteGraph
(
GraphList
*
pGraphList
)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论