递归交换二叉树左右子树:BinaryTree:Exchange the left child and right child of a binary tree
来源:互联网 发布:淘宝主图素材价格 编辑:程序博客网 时间:2024/04/29 14:09
// BTree.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct _node
{
int data;
struct _node* rch;
struct _node* lch;
}Node;
Node* InsertNode(Node* n,int d)
{
if(n)
{
if(d>n->data)
n->rch=InsertNode(n->rch,d);
else n->lch=InsertNode(n->lch,d);
}
else
{
n=(Node*)malloc(sizeof(Node));
n->data=d;
n->lch=NULL;
n->rch=NULL;
}
return n;
}
void CreateTree(Node* root,int arr[],int len)
{
for(int i=0;i<len;i++)
{
InsertNode(root,arr[i]);
}
}
void SwapChild(Node* root)
{
if(root)
{
if(root->lch!=NULL||root->rch!=NULL)
{
Node* temp;
temp=root->lch;
root->lch=root->rch;
root->rch=temp;
SwapChild(root->lch);
SwapChild(root->rch);
}
}
}
void InorderTree(Node* root)
{
if(root)
{
InorderTree(root->lch);
cout<<root->data<<" ";
InorderTree(root->rch);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[]={12,34,1,78,54,89};
Node* head=(Node*)malloc(sizeof(Node));
head->data=0;
head->lch=NULL;
head->rch=NULL;
CreateTree(head,a,6);
InorderTree(head);
cin.get();
return 0;
}
- 递归交换二叉树左右子树:BinaryTree:Exchange the left child and right child of a binary tree
- 非递归交换二叉树左右子树:BinaryTree:Exchange the left child and the right child without recursive method
- 226. Invert Binary Tree (交换二叉树左右子树)
- gxx_slide之The Child and Binary Tree
- codeforces #250E The Child and Binary Tree 快速傅里叶变换
- Codeforces 438E The Child and Binary Tree
- 二叉树交换左右子树
- A. The Child and Homework
- 用二叉树表示k叉树(left-child-right-sibling)
- CODEFORCES 438D The Child and Sequence <二叉树>
- 二叉树左右子树交换的算法
- 交换左右子树(二叉树)
- 二叉树左右子树的交换
- The Costs of Having a child
- 二叉树中所有节点的左右子树相互交换 递归与非递归程序
- 二叉树中所有节点的左右子树相互交换 递归与非递归程序
- Codeforces 437A The Child and Homework
- CodeForces 437 A. The Child and Homework
- Ubuntu下安装KDE
- c#中的Object类型
- pku 1948 Triangular Pastures(背包)
- apt命令
- wince编译问题集锦
- 递归交换二叉树左右子树:BinaryTree:Exchange the left child and right child of a binary tree
- 局域网内计算机访问问题
- Mailscanner Attempt to hide real filename extension (themeManager.x10.rel)
- WinCE5.0和WinCE6.0下编译选项介绍
- ExtJs 布局
- ExtJs 显示布局
- ExtJs 添加布局
- ExtJs 修改布局
- ubuntu9.04的十个好看主题