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

modify

上级 65a8f9c3
......@@ -2,11 +2,11 @@
/*
功能:
初始化栈。
function:
Initialize the stack.
参数:
pS -- 栈的指针
parameter:
pS -- The stack pointer
*/
void InitStack(Stack* pS)
{
......@@ -14,47 +14,47 @@ void InitStack(Stack* pS)
}
/*
功能:
将元素入栈。
function:
Push elements on the stack.
参数:
pS -- 栈的指针
Elem -- 入栈的元素
parameter:
pS -- The stack pointer
Elem -- Pushed elements
返回值:
如果插入成功返回入栈元素的值。
如果插入失败返回 -1。
returned value:
Returns the value of the pushed element if the insert succeeds.
Returns -1 if insert fails.
*/
struct BiThrNode* Push(Stack* pS, struct BiThrNode* Elem)
{
//
// 栈满,入栈失败。
// Stack full, push failed.
//
if(MAX_STACK_LENGTH < pS->top)
return 0;
pS->top++;
pS->buffer[pS->top] = Elem; // 将元素插入栈顶
pS->buffer[pS->top] = Elem; // Insert the element at the top of the stack
return Elem;
}
/*
功能:
将栈顶元素出栈
function:
Pop the top element of the stack
参数:
pS -- 栈的指针
parameter:
pS -- The stack pointer
返回值:
如果出栈成功返回出栈元素的值。
如果出栈失败返回 -1。
returned value:
If the pop succeeds, the value of the pop element is returned.
Returns -1 if pop fails.
*/
struct BiThrNode* Pop(Stack* pS)
{
struct BiThrNode* Elem;
//
// 栈为空,出栈失败
// The stack is empty and the pop fails
//
if(StackEmpty(pS))
return 0;
......@@ -66,15 +66,15 @@ struct BiThrNode* Pop(Stack* pS)
}
/*
功能:
判断栈是否为空。
function:
Determines whether the stack is empty.
参数:
pQ -- 栈的指针
parameter:
pQ -- The stack pointer
返回值:
如果栈空返回 1(真)
如果栈非空返回 0(假)
returned value:
Returns 1 if stack is empty.
Returns 0 if the stack is not empty.
*/
int StackEmpty(Stack* pS)
{
......
#include "ThreadBinaryTree.h"
Stack stack; // 栈。用于储存节点
Stack stack; // Stack. Used to store nodes
int main(int argc, char* argv[])
{
PBiThrTree pTree; // 线索二叉树指针
PBiThrTree pHead; // 指向线索二叉树的头指针
PBiThrTree pTree; // pointer to a clue binary tree
PBiThrTree pHead; // The head pointer to the clue binary tree
//
// 初始化栈
// Initialize the stack
//
InitStack(&stack);
......@@ -28,25 +28,25 @@ int main(int argc, char* argv[])
}
/*
功能:
中序遍历二叉树 pTree ,并将其线索化,pHead 指向其头节点。
function:
Middle order traverses binary trees pTree ,并将其线索化,pHead 指向其头节点.
参数:
pTree -- 线索二叉树指针。
pHead -- 线索二叉树指针,指向头节点
parameter:
pTree -- pointer to a clue binary tree.
pHead -- pointer to a clue binary tree,指向头节点
返回值:
线索化成功返回 1
线索化失败返回 0
returned value:
线索化成功返回 1.
线索化失败返回 0.
*/
int InOrderThreading(PBiThrTree pHead, PBiThrTree pTree)
{
BiThrNode* pNode; // 线索二叉树节点指针
BiThrNode* pNode; // Pointer to the clue binary tree node
BiThrNode* pPre; // pPre 指针指向刚刚访问过的节点
//
// TODO: 在此添加代码
// TODO: Add the code here
//
......@@ -56,14 +56,14 @@ int InOrderThreading(PBiThrTree pHead, PBiThrTree pTree)
}
/*
功能:
创建线索二叉树的一个节点
function:
创建线索二叉树的一个节点.
参数:
data -- 线索二叉树节点保存的数据
parameter:
data -- 线索Binary tree nodes store data
返回值:
返回节点指针
returned value:
Return node pointer
*/
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"; // 二叉树的先序序列字符串。
// 注意:只使用先序序列并不能确定唯一的二叉树。
// 所以,在叶子节点后面要紧跟两个空格,
// 并且,以字符串末尾的字符 '\0' 表示序列结束。
// 这样,先序序列就可以确定唯一的二叉树了。
static int nIndex = 0; // 二叉树先序序列的下标
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,
// 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; // The index of the binary tree first order sequence
PBiThrTree InitTree()
{
BiThrNode* pRootNode;
if('\0' == data[nIndex]) // 二叉树的先序序列字符串结束
if('\0' == data[nIndex]) // End of preordering sequence string of binary tree
pRootNode = NULL;
else
{
//
// 创建父节点
// Create parent node
//
pRootNode = (' ' == data[nIndex] ? NULL : CreateNode(data[nIndex])); // 必须忽略空节点
pRootNode = (' ' == data[nIndex] ? NULL : CreateNode(data[nIndex])); // Empty nodes must be ignored
nIndex++;
}
if(pRootNode != NULL)
{
//
// 利用递归实现先序遍历算法
// Recursion is used to implement the first order traversal algorithm
//
pRootNode->lchild = InitTree();
pRootNode->rchild = InitTree();
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论