标签:style io ar color os sp on ef amp
输入一个二叉树,输出其镜像。
解法:交换所有非叶子结点的左右结点。
#include<stdio.h>
#include<iostream>
using namespace std;
struct BinaryTreeNode{
int value;
BinaryTreeNode* left;
BinaryTreeNode* right;
};
//树的镜像
void reseverBinaryTree(BinaryTreeNode* root){
if(root==NULL||(root->left==NULL&&root->right==NULL){
return;
}
BinaryTreeNode* temp = root->right;
root->right = root->left;
root->left = temp;
if(root->left){
reseverBinaryTree(root->left);
}
if(root->right){
reseverBinaryTree(root->right);
}
}
int main(){
return 0;
}
标签:style io ar color os sp on ef amp
原文地址:http://blog.csdn.net/hackcoder/article/details/41792397