树——二叉树的镜像
来源:互联网 发布:mysql 查看表空间大小 编辑:程序博客网 时间:2024/06/04 19:17
递归实现:
void Mirrordisplay(BitTree &b) { if (!b) return;//这里要考虑到最开始b就传入了一颗空树!!! if ((b->left == nullptr) && (b->right == nullptr)) return;//到了叶子结点返回了 BitTree c = b->left; b->left = b->right; b->right = c; if (b->left) Mirrordisplay(b->left); if (b->right) Mirrordisplay(b->right);}
非递归实现:
void Mirror_nr_display(BitTree &b) { if (!b) return; stack<BitTree> s; s.push(b); while (s.size()) { BitTree pNode = s.top(); s.pop(); if ((pNode->left != nullptr) || (pNode->right != nullptr)) { BitTree temp = pNode->right; pNode->right = pNode->left; pNode->left = temp; } if (pNode->left != nullptr) s.push(pNode->left); if (pNode->right != nullptr) s.push(pNode->right); }}
阅读全文
0 0
- 二叉树系列——二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- vim 常用命令操作
- win7系统下如何查看32位还是64位
- 「python」创建模块
- caioj.1031 搜索初步
- JavaWeb开发中重新认识文件上传
- 树——二叉树的镜像
- 面向分布式商业 三业界大佬谈BCOS平台完全开源
- 流量?做用户?我们到底应该做什么?
- 欢迎使用CSDN-markdown编辑器
- JavaScript与JScript的区别
- HDU 1260
- 自绘控件(有疑问)
- 空字符对浮动的影响
- OpenGL的glPushMatrix()和glPopMatrix()矩阵栈顶操作函数详解