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

modify

上级 d7eb6d5f
......@@ -4,7 +4,7 @@ Stack stack; // Stack. Used to store nodes
int main(int argc, char* argv[])
{
CSTree pTree; // 树指针
CSTree pTree; // Pointer to a tree
//
// Initialize the stack
......@@ -12,12 +12,12 @@ int main(int argc, char* argv[])
InitStack(&stack);
//
// 创建树, 使用二叉链表表示法
// Create a tree, Use binary linked list notation
//
pTree = InitTree();
//
// 先序遍历树
// The first sequence traversal tree
//
PreOrder(pTree);
......@@ -27,7 +27,7 @@ int main(int argc, char* argv[])
OutputResult();
//
// 销毁树
// Destruction of the tree
//
DeleteTree(pTree);
......@@ -36,20 +36,20 @@ int main(int argc, char* argv[])
/*
function:
先序遍历树.Stack implementation of non - recursive algorithm.
The first sequence traversal tree.Stack implementation of non - recursive algorithm.
parameter:
pTree -- 树的指针.
pTree -- The tree pointer.
returned value:
Returns 1 if the traversal succeeds
Returns 0 if the traversal fails
*/
char g_string[MAX_NUMBER]; // 字符串.用于在遍历过程中保存树的先序序列
char g_string[MAX_NUMBER]; // String. Used to save the preordered sequence of a tree during traversal
int g_length = 0; // The string length.0 indicates an empty string
int PreOrder(CSTree pTree)
{
CSNode* pNode; // 树节点指针
CSNode* pNode; // Tree node pointer
//
// TODO: Add the code here
......@@ -60,10 +60,10 @@ int PreOrder(CSTree pTree)
/*
function:
创建树的一个节点.
Create a node in the tree.
parameter:
data -- 树节点保存的数据
data -- Data saved by tree nodes
returned value:
Return node pointer
......@@ -81,11 +81,11 @@ CSNode* CreateNode(char data)
/*
function:
创建一个子树.
Create a subtree.
parameter:
data -- 树节点保存的数据
pRootNode -- 树指针
data -- Data saved by tree nodes
pRootNode -- Pointer to a tree
returned value:
nothing
......@@ -107,13 +107,13 @@ void CreateSubTree(char* data, CSTree pRootNode)
/*
function:
使用先序遍历算法创建树.
Create a tree using a preorder traversal algorithm.
parameter:
CSTree -- 树指针
CSTree -- Pointer to a tree
returned value:
返回数据为 Key 的节点的指针
Returns a pointer to a node whose data is Key
*/
CSNode* PreOrderCreate(CSTree pTree, char Key)
{
......@@ -137,17 +137,17 @@ CSNode* PreOrderCreate(CSTree pTree, char Key)
/*
function:
利用二维数组初始化树.
Initialize the tree with a two-dimensional array.
returned value:
返回树指针
Return tree pointer
*/
const char data[MAX_NUMBER][MAX_NUMBER] =
{ { 'R', 'A', 'B', 'C' }, // 用于初始化树的二维数组,二维数组的每一行构造一棵子树,
{ 'A', 'D', 'E' }, // 第一个字符用于初始化子树的根节点,第二个字符用于初始
{ 'C', 'F' }, // 化孩子节点,其余的字符用于初始化兄弟节点.notice:第一
{ 'F', 'G', 'H', 'K' } }; // 行的第一个字符用于构造整棵树的根节点,其余行的第一个
// 字符应为之前某一行的孩子节点或兄弟节点.
{ { 'R', 'A', 'B', 'C' }, // Two dimensional array for initializing the tree, one subtree for each row of the two dimensional array,
{ 'A', 'D', 'E' }, // The first character initializes the root node of the subtree,The second character initializes the child node,
{ 'C', 'F' }, // The rest of the characters are used to initialize sibling nodes.notice:
{ 'F', 'G', 'H', 'K' } }; // The first character of the first line is used to construct the root node of the entire tree,
// The first character of the remaining lines should be the child or sibling of the previous line.
CSTree InitTree()
{
......@@ -166,10 +166,10 @@ CSTree InitTree()
/*
function:
销毁树.
Destruction of the tree.
parameter:
pTree -- 树的指针.
pTree -- The tree pointer.
returned value:
nothing
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论