二叉树的镜像
来源:互联网 发布:软件行业前景预测 编辑:程序博客网 时间:2024/05/16 12:42
#include "stdafx.h"
#include"stdio.h"
typedef struct BiTNode
{
int Value;
BiTNode* pLeft;
BiTNode* pRight;
}BiTNode, *BiTree;
void Mir(BiTNode* T)
{
if (T)
{
BiTNode* pTemp =NULL;
if (T->pLeft !=NULL ||T->pRight !=NULL)
{
pTemp = T->pLeft;
T->pLeft =T->pRight;
T->pRight = pTemp;
}
if (T->pLeft !=NULL)
{
Mir(T->pLeft);
}
if (T->pRight !=NULL)
{
Mir(T->pRight);
}
}
return;
}
void Create(BiTree &T)
{
char c;
scanf_s("%c",&c);
if ('#' == c)
{
T = NULL;
}
else
{
T = new BiTNode();
T->Value = c;
Create(T->pLeft);
Create(T->pRight);
}
return ;
}
void Print(BiTNode*T)
{
if (T)
{
printf("%c",T->Value);
Print(T->pLeft);
Print(T->pRight);
}
return;
}
int main()
{
BiTNode* T=NULL;
printf("请输入先序序列创建的二叉树:\n");
Create(T);
printf("请先序输出二叉树:\n");
Print(T);
printf("\n");
printf("请输出镜像:\n");
Mir(T);
Print(T);
printf("\n");
return 0;
}
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- 二叉树的镜像
- HDU
- Wannafly模拟赛4 A Laptop (前缀数组)
- linux基础学习1
- CodeForces 883C
- POJ 1324 BFS+状态压缩 蛇走迷宫
- 二叉树的镜像
- Android中TextView通过换行实现条目布局
- 几种最基础的字符串动态规划讲
- JVM(java 虚拟机)内存设置
- Binary Search:222. Count Complete Tree Nodes
- 【入门篇】Activiti流程部署两种方法
- 物联网的体系结构和关键技术
- Python负数下标
- 013day(学习有关一维数组的部分知识)