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

modify

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