Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab014
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab014
提交
46712a44
提交
46712a44
5月 21, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
d7eb6d5f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
25 行删除
+25
-25
main.c
main.c
+25
-25
没有找到文件。
main.c
浏览文件 @
46712a44
...
@@ -4,7 +4,7 @@ Stack stack; // Stack. Used to store nodes
...
@@ -4,7 +4,7 @@ Stack stack; // Stack. Used to store nodes
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
CSTree
pTree
;
//
树指针
CSTree
pTree
;
//
Pointer to a tree
//
//
// Initialize the stack
// Initialize the stack
...
@@ -12,12 +12,12 @@ int main(int argc, char* argv[])
...
@@ -12,12 +12,12 @@ int main(int argc, char* argv[])
InitStack
(
&
stack
);
InitStack
(
&
stack
);
//
//
//
创建树, 使用二叉链表表示法
//
Create a tree, Use binary linked list notation
//
//
pTree
=
InitTree
();
pTree
=
InitTree
();
//
//
//
先序遍历树
//
The first sequence traversal tree
//
//
PreOrder
(
pTree
);
PreOrder
(
pTree
);
...
@@ -27,7 +27,7 @@ int main(int argc, char* argv[])
...
@@ -27,7 +27,7 @@ int main(int argc, char* argv[])
OutputResult
();
OutputResult
();
//
//
//
销毁树
//
Destruction of the tree
//
//
DeleteTree
(
pTree
);
DeleteTree
(
pTree
);
...
@@ -36,20 +36,20 @@ int main(int argc, char* argv[])
...
@@ -36,20 +36,20 @@ int main(int argc, char* argv[])
/*
/*
function:
function:
先序遍历树
.Stack implementation of non - recursive algorithm.
The first sequence traversal tree
.Stack implementation of non - recursive algorithm.
parameter:
parameter:
pTree --
树的指针
.
pTree --
The tree pointer
.
returned value:
returned value:
Returns 1 if the traversal succeeds
Returns 1 if the traversal succeeds
Returns 0 if the traversal fails
Returns 0 if the traversal fails
*/
*/
char
g_string
[
MAX_NUMBER
];
//
字符串.用于在遍历过程中保存树的先序序列
char
g_string
[
MAX_NUMBER
];
//
String. Used to save the preordered sequence of a tree during traversal
int
g_length
=
0
;
// The string length.0 indicates an empty string
int
g_length
=
0
;
// The string length.0 indicates an empty string
int
PreOrder
(
CSTree
pTree
)
int
PreOrder
(
CSTree
pTree
)
{
{
CSNode
*
pNode
;
//
树节点指针
CSNode
*
pNode
;
//
Tree node pointer
//
//
// TODO: Add the code here
// TODO: Add the code here
...
@@ -60,10 +60,10 @@ int PreOrder(CSTree pTree)
...
@@ -60,10 +60,10 @@ int PreOrder(CSTree pTree)
/*
/*
function:
function:
创建树的一个节点
.
Create a node in the tree
.
parameter:
parameter:
data --
树节点保存的数据
data --
Data saved by tree nodes
returned value:
returned value:
Return node pointer
Return node pointer
...
@@ -81,11 +81,11 @@ CSNode* CreateNode(char data)
...
@@ -81,11 +81,11 @@ CSNode* CreateNode(char data)
/*
/*
function:
function:
创建一个子树
.
Create a subtree
.
parameter:
parameter:
data --
树节点保存的数据
data --
Data saved by tree nodes
pRootNode --
树指针
pRootNode --
Pointer to a tree
returned value:
returned value:
nothing
nothing
...
@@ -107,13 +107,13 @@ void CreateSubTree(char* data, CSTree pRootNode)
...
@@ -107,13 +107,13 @@ void CreateSubTree(char* data, CSTree pRootNode)
/*
/*
function:
function:
使用先序遍历算法创建树
.
Create a tree using a preorder traversal algorithm
.
parameter:
parameter:
CSTree --
树指针
CSTree --
Pointer to a tree
returned value:
returned value:
返回数据为 Key 的节点的指针
Returns a pointer to a node whose data is Key
*/
*/
CSNode
*
PreOrderCreate
(
CSTree
pTree
,
char
Key
)
CSNode
*
PreOrderCreate
(
CSTree
pTree
,
char
Key
)
{
{
...
@@ -137,17 +137,17 @@ CSNode* PreOrderCreate(CSTree pTree, char Key)
...
@@ -137,17 +137,17 @@ CSNode* PreOrderCreate(CSTree pTree, char Key)
/*
/*
function:
function:
利用二维数组初始化树
.
Initialize the tree with a two-dimensional array
.
returned value:
returned value:
返回树指针
Return tree pointer
*/
*/
const
char
data
[
MAX_NUMBER
][
MAX_NUMBER
]
=
const
char
data
[
MAX_NUMBER
][
MAX_NUMBER
]
=
{
{
'R'
,
'A'
,
'B'
,
'C'
},
//
用于初始化树的二维数组,二维数组的每一行构造一棵子树
,
{
{
'R'
,
'A'
,
'B'
,
'C'
},
//
Two dimensional array for initializing the tree, one subtree for each row of the two dimensional array
,
{
'A'
,
'D'
,
'E'
},
//
第一个字符用于初始化子树的根节点,第二个字符用于初始
{
'A'
,
'D'
,
'E'
},
//
The first character initializes the root node of the subtree,The second character initializes the child node,
{
'C'
,
'F'
},
//
化孩子节点,其余的字符用于初始化兄弟节点.notice:第一
{
'C'
,
'F'
},
//
The rest of the characters are used to initialize sibling nodes.notice:
{
'F'
,
'G'
,
'H'
,
'K'
}
};
//
行的第一个字符用于构造整棵树的根节点,其余行的第一个
{
'F'
,
'G'
,
'H'
,
'K'
}
};
//
The first character of the first line is used to construct the root node of the entire tree,
//
字符应为之前某一行的孩子节点或兄弟节点
.
//
The first character of the remaining lines should be the child or sibling of the previous line
.
CSTree
InitTree
()
CSTree
InitTree
()
{
{
...
@@ -166,10 +166,10 @@ CSTree InitTree()
...
@@ -166,10 +166,10 @@ CSTree InitTree()
/*
/*
function:
function:
销毁树
.
Destruction of the tree
.
parameter:
parameter:
pTree --
树的指针
.
pTree --
The tree pointer
.
returned value:
returned value:
nothing
nothing
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论