剑指Offer-19-二叉树的镜像
来源:互联网 发布:python pipes 编辑:程序博客网 时间:2024/05/29 04:42
题目:
完成一个函数,输入一个二叉树,该函数输入二叉树的镜像。
原二叉树 8 1 23 4则输出 8 2 1 4 3
思路:
前序遍历二叉树的每个结点,如果遍历到的结点有子结点,就交换它的两个左右子节点,当交换完所有非叶子结点的左右子结点之后,就得到了二叉树的镜像。
#include <iostream>using namespace std;struct BinaryTreeNode { int m_nValue; struct BinaryTreeNode *m_pLeft; struct BinaryTreeNode *m_pRight;};void MirrorRecursively(BinaryTreeNode *pNode) { if(pNode == NULL) return; if(pNode->m_pLeft==NULL && pNode->m_pRight==NULL) return; BinaryTreeNode *t = pNode->m_pLeft; pNode->m_pLeft = pNode->m_pRight; pNode->m_pRight = t; MirrorRecursively(pNode->m_pLeft); MirrorRecursively(pNode->m_pRight);}
0 0
- 【剑指offer】二叉树的镜像
- [剑指Offer]二叉树的镜像
- 剑指offer--二叉树的镜像
- 剑指Offer-二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指 offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指offer 二叉树的镜像
- [剑指offer]二叉树的镜像
- 《剑指offer》-二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer|二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指Offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer-二叉树的镜像
- 剑指offer 二叉树的镜像
- UILongPressGestureRecognizer的介绍
- Unreal Engine 4 蓝图脚本学习 添加脚本使actor来回移动 (2)
- 解决spring、springMVC重复扫描导致事务失效的问题
- cocos2dx游戏资源加密之XXTEA
- 推荐些好的博客和iOS学习网站(有的需要CrossingWall)
- 剑指Offer-19-二叉树的镜像
- RAC 11g的基本概念四
- git diff 四种比较方式
- hdoj 1004 Let the Balloon Rise 解题报告
- 国际标准行业分类(ISIC Rev 4.0)
- github fork项目后与原项目进行同步
- ARM开发板定位参数解释
- RAC 11g的基本概念三
- 大二训练第二周 - Distance Queries lca