问题描述:
给定两个二叉树的根节点,判断两棵二叉树是否相等(左右相等或者左右交换后对应相等),代码如下:
#include <cstdio>
using namespace std;
typedef struct TreeNode{
char data;
TreeNode *leftchild;
TreeNode *rightchild;
}TreeNode;
TreeNode * CreateBTree(){
TreeNode * root = NULL;
char temp;
scanf("%c", &temp);
if(temp != '#'){
root = new TreeNode();
root->data = temp;
root->leftchild = CreateBTree();
root->rightchild = CreateBTree();
return root;
}
else{
return NULL;
}
}
void PrePrint(TreeNode *root){
if (root != NULL){
printf("%c", root->data);
PrePrint(root->leftchild);
PrePrint(root->rightchild);
}
}
int