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

modify

上级 99aa5c57
...@@ -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 CSNode* Push(Stack* pS, struct CSNode* Elem) struct CSNode* Push(Stack* pS, struct CSNode* 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 CSNode* Pop(Stack* pS) struct CSNode* Pop(Stack* pS)
{ {
struct CSNode* Elem; struct CSNode* Elem;
// //
// 栈为空,出栈失败 // The stack is empty and the pop fails
// //
if(StackEmpty(pS)) if(StackEmpty(pS))
return 0; return 0;
...@@ -66,15 +66,15 @@ struct CSNode* Pop(Stack* pS) ...@@ -66,15 +66,15 @@ struct CSNode* 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 "CSTree.h" #include "CSTree.h"
Stack stack; // 栈。用于储存节点 Stack stack; // Stack. Used to store nodes
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
CSTree pTree; // 树指针 CSTree pTree; // 树指针
// //
// 初始化栈 // Initialize the stack
// //
InitStack(&stack); InitStack(&stack);
...@@ -22,7 +22,7 @@ int main(int argc, char* argv[]) ...@@ -22,7 +22,7 @@ int main(int argc, char* argv[])
PreOrder(pTree); PreOrder(pTree);
// //
// 输出结果 // output result
// //
OutputResult(); OutputResult();
...@@ -35,38 +35,38 @@ int main(int argc, char* argv[]) ...@@ -35,38 +35,38 @@ int main(int argc, char* argv[])
} }
/* /*
功能: function:
先序遍历树。利用栈实现非递归算法。 先序遍历树.Stack implementation of non - recursive algorithm.
参数: parameter:
pTree -- 树的指针 pTree -- 树的指针.
返回值: returned value:
如果遍历成功返回 1 Returns 1 if the traversal succeeds
如果遍历失败返回 0 Returns 0 if the traversal fails
*/ */
char g_string[MAX_NUMBER]; // 字符串用于在遍历过程中保存树的先序序列 char g_string[MAX_NUMBER]; // 字符串.用于在遍历过程中保存树的先序序列
int g_length = 0; // 字符串长度。0 表示空字符串 int g_length = 0; // The string length.0 indicates an empty string
int PreOrder(CSTree pTree) int PreOrder(CSTree pTree)
{ {
CSNode* pNode; // 树节点指针 CSNode* pNode; // 树节点指针
// //
// TODO: 在此添加代码 // TODO: Add the code here
// //
return 0; return 0;
} }
/* /*
功能: function:
创建树的一个节点 创建树的一个节点.
参数: parameter:
data -- 树节点保存的数据 data -- 树节点保存的数据
返回值: returned value:
返回节点指针 Return node pointer
*/ */
CSNode* CreateNode(char data) CSNode* CreateNode(char data)
{ {
...@@ -80,15 +80,15 @@ CSNode* CreateNode(char data) ...@@ -80,15 +80,15 @@ CSNode* CreateNode(char data)
} }
/* /*
功能: function:
创建一个子树 创建一个子树.
参数: parameter:
data -- 树节点保存的数据 data -- 树节点保存的数据
pRootNode -- 树指针 pRootNode -- 树指针
返回值: returned value:
nothing
*/ */
void CreateSubTree(char* data, CSTree pRootNode) void CreateSubTree(char* data, CSTree pRootNode)
{ {
...@@ -106,13 +106,13 @@ void CreateSubTree(char* data, CSTree pRootNode) ...@@ -106,13 +106,13 @@ void CreateSubTree(char* data, CSTree pRootNode)
} }
/* /*
功能: function:
使用先序遍历算法创建树 使用先序遍历算法创建树.
参数: parameter:
CSTree -- 树指针 CSTree -- 树指针
返回值: returned value:
返回数据为 Key 的节点的指针 返回数据为 Key 的节点的指针
*/ */
CSNode* PreOrderCreate(CSTree pTree, char Key) CSNode* PreOrderCreate(CSTree pTree, char Key)
...@@ -136,18 +136,18 @@ CSNode* PreOrderCreate(CSTree pTree, char Key) ...@@ -136,18 +136,18 @@ CSNode* PreOrderCreate(CSTree pTree, char Key)
} }
/* /*
功能: function:
利用二维数组初始化树 利用二维数组初始化树.
返回值: returned value:
返回树指针 返回树指针
*/ */
const char data[MAX_NUMBER][MAX_NUMBER] = const char data[MAX_NUMBER][MAX_NUMBER] =
{ { 'R', 'A', 'B', 'C' }, // 用于初始化树的二维数组二维数组的每一行构造一棵子树, { { 'R', 'A', 'B', 'C' }, // 用于初始化树的二维数组,二维数组的每一行构造一棵子树,
{ 'A', 'D', 'E' }, // 第一个字符用于初始化子树的根节点第二个字符用于初始 { 'A', 'D', 'E' }, // 第一个字符用于初始化子树的根节点,第二个字符用于初始
{ 'C', 'F' }, // 化孩子节点,其余的字符用于初始化兄弟节点。注意:第一 { 'C', 'F' }, // 化孩子节点,其余的字符用于初始化兄弟节点.notice:第一
{ 'F', 'G', 'H', 'K' } }; // 行的第一个字符用于构造整棵树的根节点其余行的第一个 { 'F', 'G', 'H', 'K' } }; // 行的第一个字符用于构造整棵树的根节点,其余行的第一个
// 字符应为之前某一行的孩子节点或兄弟节点 // 字符应为之前某一行的孩子节点或兄弟节点.
CSTree InitTree() CSTree InitTree()
{ {
...@@ -165,19 +165,19 @@ CSTree InitTree() ...@@ -165,19 +165,19 @@ CSTree InitTree()
} }
/* /*
功能: function:
销毁树 销毁树.
参数: parameter:
pTree -- 树的指针 pTree -- 树的指针.
返回值: returned value:
nothing
*/ */
void DeleteTree(CSTree pTree) void DeleteTree(CSTree pTree)
{ {
// //
// 利用递归实现后序遍历算法 // The sequential traversal algorithm is implemented by recursion
// //
if(pTree != NULL) if(pTree != NULL)
{ {
...@@ -189,14 +189,14 @@ void DeleteTree(CSTree pTree) ...@@ -189,14 +189,14 @@ void DeleteTree(CSTree pTree)
} }
/* /*
功能: function:
输出结果。 output result.
参数: parameter:
nothing
返回值: returned value:
nothing
*/ */
void OutputResult() void OutputResult()
{ {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论