牵丝戏  

1.学习总结

1.1树结构思维导图

1.2 树结构学习体会

1.树是一种非线性结构,其定义是递归的,在学习过程中,需要注意递归的调用。

2.困难:建树并解决问题时没有思路。

3.求解哈夫曼编码以及解决等价问题。

2.PTA实验作业

2.1 题目1:

6-3 先序输出叶结点

2.2 设计思路(伪代码或流程图)

void PreorderPrintLeaves(BinTree BT)
{
if(BT是否为空)

return;
if(判断是否为叶子节点)
printf(输出叶子节点);
递归上述循环
return;
}

2.3 代码截图

2.4 PTA提交列表说明。

2.1 题目2:

6-4 jmu-ds-表达式树

2.2 设计思路(伪代码或流程图)

double EvaluateExTree(BTree T){

a,b,赋值

a=EvaluateExTree(T->lchild);
b=EvaluateExTree(T->rchild);
switch(判断树的计算)
{
case '+':
返回 a+b;
case '-':
返回 a-b;
case '*':
返回 a*b;
case '/':
 返回 a/b;
}

}

2.3 代码截图

 

 

2.4 PTA提交列表说明。

2.1 题目3:

7-1 还原二叉树

2.2 设计思路(伪代码或流程图)


BinTree CreateTree(char *pre,char *in,int n)
{
BinTree T;
T->data=*pre;
T->Left :

T->Right ://对先序,中序遍历进行判断保存到T中
return T;
}

int GetHeight(BinTree T)
{
if(树为空)return 0;
l=GetHeight(T->Left);
r=GetHeight(T->Right);
存储高度max
return max+1;
}

2.3 代码截图

2.4 PTA提交列表说明。

 

3.截图本周题目集的PTA最后排名

3.1 PTA排名截图

3.2 我的总分:1.5

4. 阅读代码(必做)

二叉树的宽度

1 int treeWidth(Bitree *root){
 2   if(!root){
 3     return 0;
 4   }
 5   int width = 0;
 6   int maxWidth = 0;
 7   queue<Bitree *> Q;
 8   Bitree *p = nullptr;
 9   Q.push(root);
10   while(!Q.empty()){
11     width = Q.size();
12     if(maxWidth < width){
13       maxWidth = width;
14     }
15     for(int i=0; i<width; i++){
16       p = Q.front();
17       Q.pop();
18       if(p->left){
19         Q.push(p->left);
20       }
21       if(p->right){
22         Q.push(p->right);
23       }
24     }
25   }
26   return maxWidth;
27 }

代码功能:求二叉树的高度

优点:可以清晰地知道每一层中节点的多少,自然也知晓树的宽度。

5. 代码Git提交记录截图

 

posted on 2018-05-05 20:35  牵丝戏  阅读(285)  评论(0编辑  收藏  举报