Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab012
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab012
提交
f7ea3af0
提交
f7ea3af0
5月 20, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
65a8f9c3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
63 行增加
和
63 行删除
+63
-63
Stack.c
Stack.c
+29
-29
main.c
main.c
+34
-34
没有找到文件。
Stack.c
浏览文件 @
f7ea3af0
...
@@ -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.
*/
*/
struct
BiThrNode
*
Push
(
Stack
*
pS
,
struct
BiThrNode
*
Elem
)
struct
BiThrNode
*
Push
(
Stack
*
pS
,
struct
BiThrNode
*
Elem
)
{
{
//
//
//
栈满,入栈失败。
//
Stack full, push failed.
//
//
if
(
MAX_STACK_LENGTH
<
pS
->
top
)
if
(
MAX_STACK_LENGTH
<
pS
->
top
)
return
0
;
return
0
;
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.
*/
*/
struct
BiThrNode
*
Pop
(
Stack
*
pS
)
struct
BiThrNode
*
Pop
(
Stack
*
pS
)
{
{
struct
BiThrNode
*
Elem
;
struct
BiThrNode
*
Elem
;
//
//
//
栈为空,出栈失败
//
The stack is empty and the pop fails
//
//
if
(
StackEmpty
(
pS
))
if
(
StackEmpty
(
pS
))
return
0
;
return
0
;
...
@@ -66,15 +66,15 @@ struct BiThrNode* Pop(Stack* pS)
...
@@ -66,15 +66,15 @@ struct BiThrNode* 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
浏览文件 @
f7ea3af0
#include "ThreadBinaryTree.h"
#include "ThreadBinaryTree.h"
Stack
stack
;
//
栈。用于储存节点
Stack
stack
;
//
Stack. Used to store nodes
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
PBiThrTree
pTree
;
//
线索二叉树指针
PBiThrTree
pTree
;
//
pointer to a clue binary tree
PBiThrTree
pHead
;
//
指向线索二叉树的头指针
PBiThrTree
pHead
;
//
The head pointer to the clue binary tree
//
//
//
初始化栈
//
Initialize the stack
//
//
InitStack
(
&
stack
);
InitStack
(
&
stack
);
...
@@ -28,25 +28,25 @@ int main(int argc, char* argv[])
...
@@ -28,25 +28,25 @@ int main(int argc, char* argv[])
}
}
/*
/*
功能:
function:
中序遍历二叉树 pTree ,并将其线索化,pHead 指向其头节点。
Middle order traverses binary trees pTree ,并将其线索化,pHead 指向其头节点.
参数:
parameter:
pTree --
线索二叉树指针。
pTree --
pointer to a clue binary tree.
pHead --
线索二叉树指针,
指向头节点
pHead --
pointer to a clue binary tree,
指向头节点
返回值:
returned value:
线索化成功返回 1
。
线索化成功返回 1
.
线索化失败返回 0
。
线索化失败返回 0
.
*/
*/
int
InOrderThreading
(
PBiThrTree
pHead
,
PBiThrTree
pTree
)
int
InOrderThreading
(
PBiThrTree
pHead
,
PBiThrTree
pTree
)
{
{
BiThrNode
*
pNode
;
//
线索二叉树节点指针
BiThrNode
*
pNode
;
//
Pointer to the clue binary tree node
BiThrNode
*
pPre
;
// pPre 指针指向刚刚访问过的节点
BiThrNode
*
pPre
;
// pPre 指针指向刚刚访问过的节点
//
//
// TODO:
在此添加代码
// TODO:
Add the code here
//
//
...
@@ -56,14 +56,14 @@ int InOrderThreading(PBiThrTree pHead, PBiThrTree pTree)
...
@@ -56,14 +56,14 @@ int InOrderThreading(PBiThrTree pHead, PBiThrTree pTree)
}
}
/*
/*
功能:
function:
创建线索二叉树的一个节点
。
创建线索二叉树的一个节点
.
参数:
parameter:
data -- 线索
二叉树节点保存的数据
data -- 线索
Binary tree nodes store data
返回值:
returned value:
返回节点指针
Return node pointer
*/
*/
BiThrNode
*
CreateNode
(
ElemType
data
)
BiThrNode
*
CreateNode
(
ElemType
data
)
{
{
...
@@ -79,37 +79,37 @@ BiThrNode* CreateNode(ElemType data)
...
@@ -79,37 +79,37 @@ BiThrNode* CreateNode(ElemType data)
}
}
/*
/*
功能:
function:
利用二叉树的先序序列创建一棵二叉树
。
利用二叉树的先序序列创建一棵二叉树
.
返回值:
returned value:
返回
二叉树指针
返回
pointer to a binary tree
*/
*/
static
const
char
*
data
=
"-+ *b -c d /e"
;
//
二叉树的先序序列字符串。
static
const
char
*
data
=
"-+ *b -c d /e"
;
//
A binary tree preordered sequence string.
//
注意:只使用先序序列并不能确定唯一的二叉树。
//
notice:Using only preordered sequences does not determine a unique binary tree.
//
所以,在叶子节点后面要紧跟两个空格,
//
So, two Spaces after the leaf node,
//
并且,以字符串末尾的字符 '\0' 表示序列结束。
//
Also, the sequence ends with the character '\0' at the end of the string.
//
这样,先序序列就可以确定唯一的二叉树了。
//
In this way, the preordering sequence determines the unique binary tree.
static
int
nIndex
=
0
;
//
二叉树先序序列的下标
static
int
nIndex
=
0
;
//
The index of the binary tree first order sequence
PBiThrTree
InitTree
()
PBiThrTree
InitTree
()
{
{
BiThrNode
*
pRootNode
;
BiThrNode
*
pRootNode
;
if
(
'\0'
==
data
[
nIndex
])
//
二叉树的先序序列字符串结束
if
(
'\0'
==
data
[
nIndex
])
//
End of preordering sequence string of binary tree
pRootNode
=
NULL
;
pRootNode
=
NULL
;
else
else
{
{
//
//
//
创建父节点
//
Create parent node
//
//
pRootNode
=
(
' '
==
data
[
nIndex
]
?
NULL
:
CreateNode
(
data
[
nIndex
]));
//
必须忽略空节点
pRootNode
=
(
' '
==
data
[
nIndex
]
?
NULL
:
CreateNode
(
data
[
nIndex
]));
//
Empty nodes must be ignored
nIndex
++
;
nIndex
++
;
}
}
if
(
pRootNode
!=
NULL
)
if
(
pRootNode
!=
NULL
)
{
{
//
//
//
利用递归实现先序遍历算法
//
Recursion is used to implement the first order traversal algorithm
//
//
pRootNode
->
lchild
=
InitTree
();
pRootNode
->
lchild
=
InitTree
();
pRootNode
->
rchild
=
InitTree
();
pRootNode
->
rchild
=
InitTree
();
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论