Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab012
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab012
提交
46b215ee
提交
46b215ee
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
dc2d0a5c
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
28 行增加
和
34 行删除
+28
-34
Stack.c
Stack.c
+6
-3
Stack.h
Stack.h
+4
-12
ThreadBinaryTree.h
ThreadBinaryTree.h
+2
-7
main.c
main.c
+16
-12
没有找到文件。
Stack.c
浏览文件 @
46b215ee
#include "Stack.h"
#include "Stack.h"
/*
/*
function:
function:
Initialize the stack.
Initialize the stack.
...
@@ -30,8 +29,10 @@ struct BiThrNode* Push(Stack* pS, struct BiThrNode* Elem)
...
@@ -30,8 +29,10 @@ struct BiThrNode* Push(Stack* pS, struct BiThrNode* Elem)
//
//
// Stack full, push failed.
// 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
;
// Insert the element at the top of the stack
pS
->
buffer
[
pS
->
top
]
=
Elem
;
// Insert the element at the top of the stack
...
@@ -56,8 +57,10 @@ struct BiThrNode* Pop(Stack* pS)
...
@@ -56,8 +57,10 @@ struct BiThrNode* Pop(Stack* pS)
//
//
// The stack is empty and the pop fails
// The stack is empty and the pop fails
//
//
if
(
StackEmpty
(
pS
))
if
(
StackEmpty
(
pS
))
{
return
0
;
return
0
;
}
Elem
=
pS
->
buffer
[
pS
->
top
];
Elem
=
pS
->
buffer
[
pS
->
top
];
pS
->
top
--
;
pS
->
top
--
;
...
...
Stack.h
浏览文件 @
46b215ee
#ifndef STACK_H_
#ifndef STACK_H_
#define STACK_H_
#define STACK_H_
//
//
// Include the C standard library header file here
// Include the C standard library header file here
//
//
//
//
// Other header files are included here
// Other header files are included here
//
//
//
//
// Define the data structure here
// Define the data structure here
//
//
...
@@ -22,12 +17,13 @@
...
@@ -22,12 +17,13 @@
// Stack
// Stack
struct
BiThrNode
;
struct
BiThrNode
;
typedef
struct
Stack
{
typedef
struct
Stack
{
struct
BiThrNode
*
buffer
[
MAX_STACK_LENGTH
];
// Stack buffer
struct
BiThrNode
*
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
;
}
Stack
;
//
//
// Declare the function here
// Declare the function here
//
//
...
@@ -37,12 +33,8 @@ struct BiThrNode* Pop(Stack* pS);
...
@@ -37,12 +33,8 @@ struct BiThrNode* Pop(Stack* pS);
int
StackEmpty
(
Stack
*
pS
);
int
StackEmpty
(
Stack
*
pS
);
struct
BiThrNode
*
Push
(
Stack
*
pS
,
struct
BiThrNode
*
Elem
);
struct
BiThrNode
*
Push
(
Stack
*
pS
,
struct
BiThrNode
*
Elem
);
//
//
// Declare global variables here
// Declare global variables here
//
//
#endif
/* STACK_H_ */
#endif
/* STACK_H_ */
ThreadBinaryTree.h
浏览文件 @
46b215ee
#ifndef THREADBINARYTREE_H_
#ifndef THREADBINARYTREE_H_
#define THREADBINARYTREE_H_
#define THREADBINARYTREE_H_
//
//
// Include the C standard library header file here
// Include the C standard library header file here
//
//
#include <stdio.h>
#include <stdio.h>
//
//
// Other header files are included here
// Other header files are included here
//
//
#include "Stack.h"
#include "Stack.h"
//
//
// Define the data structure here
// Define the data structure here
//
//
...
@@ -26,7 +22,8 @@
...
@@ -26,7 +22,8 @@
typedef
char
ElemType
;
typedef
char
ElemType
;
typedef
unsigned
int
PtrTag
;
typedef
unsigned
int
PtrTag
;
typedef
struct
_BiThrNode
{
typedef
struct
_BiThrNode
{
ElemType
data
;
// Binary tree node data
ElemType
data
;
// Binary tree node data
struct
_BiThrNode
*
lchild
;
// Left child pointer
struct
_BiThrNode
*
lchild
;
// Left child pointer
struct
_BiThrNode
*
rchild
;
// Right child pointer
struct
_BiThrNode
*
rchild
;
// Right child pointer
...
@@ -48,8 +45,6 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree);
...
@@ -48,8 +45,6 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree);
// Declare global variables here
// Declare global variables here
//
//
extern
Stack
stack
;
extern
Stack
stack
;
#endif
/* THREADBINARYTREE_H_ */
#endif
/* THREADBINARYTREE_H_ */
main.c
浏览文件 @
46b215ee
...
@@ -95,18 +95,20 @@ PBiThrTree InitTree()
...
@@ -95,18 +95,20 @@ PBiThrTree InitTree()
{
{
BiThrNode
*
pRootNode
;
BiThrNode
*
pRootNode
;
if
(
'\0'
==
data
[
nIndex
])
// End of preordering sequence string of binary tree
if
(
'\0'
==
data
[
nIndex
])
// End of preordering sequence string of binary tree
{
pRootNode
=
NULL
;
pRootNode
=
NULL
;
}
else
else
{
{
//
//
// Create parent node
// Create parent node
, Empty nodes must be ignored
//
//
pRootNode
=
(
' '
==
data
[
nIndex
]
?
NULL
:
CreateNode
(
data
[
nIndex
]));
// Empty nodes must be ignored
pRootNode
=
(
' '
==
data
[
nIndex
]
?
NULL
:
CreateNode
(
data
[
nIndex
]));
nIndex
++
;
nIndex
++
;
}
}
if
(
pRootNode
!=
NULL
)
if
(
pRootNode
!=
NULL
)
{
{
//
//
// Recursion is used to implement the first order traversal algorithm
// Recursion is used to implement the first order traversal algorithm
...
@@ -123,22 +125,22 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree)
...
@@ -123,22 +125,22 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree)
BiThrNode
*
pNode2
;
BiThrNode
*
pNode2
;
BiThrNode
*
pPreNode2
;
BiThrNode
*
pPreNode2
;
if
(
pHead
->
lchild
==
NULL
)
if
(
pHead
->
lchild
==
NULL
)
{
{
return
0
;
return
0
;
}
}
pNode2
=
pHead
->
lchild
;
pNode2
=
pHead
->
lchild
;
pPreNode2
=
NULL
;
pPreNode2
=
NULL
;
while
(
1
)
while
(
1
)
{
{
while
(
1
)
while
(
1
)
{
{
if
(
pNode2
->
ltag
==
0
&&
(
pPreNode2
==
NULL
||
pPreNode2
!=
pNode2
->
lchild
))
if
(
pNode2
->
ltag
==
0
&&
(
pPreNode2
==
NULL
||
pPreNode2
!=
pNode2
->
lchild
))
{
{
pNode2
=
pNode2
->
lchild
;
pNode2
=
pNode2
->
lchild
;
}
}
else
if
(
pNode2
->
rtag
==
0
)
else
if
(
pNode2
->
rtag
==
0
)
{
{
printf
(
"%c "
,
pNode2
->
data
);
printf
(
"%c "
,
pNode2
->
data
);
pNode2
=
pNode2
->
rchild
;
pNode2
=
pNode2
->
rchild
;
...
@@ -155,13 +157,15 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree)
...
@@ -155,13 +157,15 @@ void OutputResult(PBiThrTree pHead, PBiThrTree pTree)
pNode2
=
pNode2
->
rchild
;
pNode2
=
pNode2
->
rchild
;
if
(
pNode2
==
pTree
)
if
(
pNode2
==
pTree
)
{
if
(
pNode2
->
data
!=
'\0'
)
{
{
if
(
pNode2
->
data
!=
'\0'
)
printf
(
"%c "
,
pNode2
->
data
);
printf
(
"%c "
,
pNode2
->
data
);
}
pNode2
=
pNode2
->
rchild
;
pNode2
=
pNode2
->
rchild
;
}
}
if
(
pNode2
==
pHead
)
if
(
pNode2
==
pHead
)
{
{
break
;
break
;
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论