二叉树镜像 -- 递归法
来源:互联网 发布:怎么在淘宝网开网店 编辑:程序博客网 时间:2024/06/18 09:57
#include <cstdio> #include <iostream> #include <vector> #include <set>#include <algorithm>#include <stack>#include <string>#include <queue>#include <unordered_map>#include <iterator>using namespace std;#define N 100int n , m;typedef struct node{ int data; struct node* left; struct node* right; node(int _data = -1) { data = _data; left = NULL; right = NULL; }}Bnode;//递归镜像 void bmirror(Bnode* root){ if(root == NULL) return ; Bnode* left = root->left ; Bnode* right = root->right; bmirror(left); bmirror(right); root->left = right; // 左右子树交换 root->right = left;}int main() { Bnode* b1 = new node(1); Bnode* b2 = new node(2); Bnode* b3 = new node(3); Bnode* b4 = new node(4); Bnode* b5 = new node(5); Bnode* b6 = new node(6); b1->left = b2; b1->right = b3; b2->left = b4; b2->right = b5; b3->left = b6; /* 1 1 / \ / \ 2 3 3 2 / \ / 镜像 \ / \ 4 5 6 6 5 4 */ bmirror(b1); return 0; }
0 0
- 二叉树镜像 -- 递归法
- 二叉树镜像(递归与非递归)
- C++递归求二叉树镜像
- 二叉树镜像使用递归法和循环法
- 求二叉树镜像 -- 采用递归和非递归方法
- 面试题之二叉树镜像(递归,非递归),深度
- 二叉树镜像之递归、栈、队列实现
- 二叉树镜像,递归和循环实现
- 二叉树镜像的非递归实现
- 递归法(非递归法)遍历二叉树
- 二叉树(BiTree)(递归与非递归法)
- 【数据结构】递归与非递归法遍历二叉树
- 用递归法遍历二叉树
- 用括号法递归建立二叉树
- 二叉树(4)非递归法遍历二叉树
- 递归、非递归~二叉树
- 二叉树 递归 非递归
- 二叉树递归非递归遍历(递归前中后,非递归前中后,层次遍历,凹入打印法等)
- hdu 2222 Keywords Search (ac自动机)
- hdoj 1711 Number Sequence【kmp(数字数组)】
- 回调机制的实现,即细看setOnClickListener怎么运行
- 两个链表的第一个公共结点
- 违例差错控制
- 二叉树镜像 -- 递归法
- android:installLocation简析
- android app反编译
- 线程协作-生产者/消费者问题
- 【Hadoop】Avro源码分析(一):Schema
- iphone开发之表格组件UITableView的使用(七)实现数据刷新
- quartz 相关源码解析
- LeetCode----Integer to Roman
- CCE(3)