提交 f7ea3af0 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 65a8f9c3
...@@ -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)
{ {
......
#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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论