码迷,mamicode.com
首页 > 其他好文 > 详细

博客作业04--树

时间:2018-05-05 20:48:39      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:理解   代码   3.1   列表   typedef   rsa   pre   博客   eve   

1.学习总结

1.1树结构思维导图

1.2 树结构学习体会

2.PTA实验作业

题目1:

设计思路

代码截图

PTA提交列表说明

题目1:

设计思路

代码截图

PTA提交列表说明

题目1:

设计思路

代码截图

PTA提交列表说明

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

3.1 PTA排名

3.2 我的得分:

4. 阅读代码

问题:求反转二叉树
``

include

include

typedef struct Tree {
int val;
struct Tree* left;
struct Tree* right;
}Tree;

void CreateBiTree(Tree**T)
{
int val;

scanf("%d", &val);
if(val == -1)
    *T = NULL;
else
{
    *T = (Tree *)malloc(sizeof(Tree));
    (*T)->val = val;
    CreateBiTree(&(*T)->left);
    CreateBiTree(&(*T)->right);
}

}

void ExchangeLeftRight(Tree **root)
{
Tree * node = (root)->right;
(
root)->right = (root)->left;
(
root)->left = node;
}

void RecursiveReversal(Tree *root) //反转二叉树
{
if (root != NULL)
{
ExchangeLeftRight(&root);
RecursiveReversal(root->left);
RecursiveReversal(root->right);
}
}

void Print(Tree*root)
{
if (root != NULL)
{
Print(root->left);
printf("%d ", root->val);
Print(root->right);
}
}

int main()
{
Tree* root;

CreateBiTree(&root);
Print(root);
printf("\n");
RecursiveReversal(root);
Print(root);

return 0;

}
这一题主要用到的是递归的算法,只要把左右子树调换,并不是很难,但是我对递归的方法理解的不够好,所以选这题

5. 代码Git提交记录截图

博客作业04--树

标签:理解   代码   3.1   列表   typedef   rsa   pre   博客   eve   

原文地址:https://www.cnblogs.com/Airoure/p/8995747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!