#include<iostream>
using namespace std;
struct BiNode
{
char data;
BiNode *lchild,*rchild;
};
class BiTree
{
public:
BiTree(){root=Creat(root);}
void Change(){change(root);}
void Print(){print(root);}
int Empty()
{
if(root==NULL)
return 1;
else
return 0;
}
private:
BiNode *root;
BiNode* Creat(BiNode *bt);
void change(BiNode *bt);
void print(BiNode *bt);
};
BiNode *BiTree::Creat(BiNode *bt)
{
char ch;
cin>>ch;
if(ch=='#')
return NULL;
else
{
bt=new BiNode;
bt->data=ch;
bt->lchild=Creat(bt->lchild);
bt->rchild=Creat(bt->rchild);
}
return bt;
}
void BiTree::change(BiNode *bt)
{
BiNode *temp;
if(bt != NULL)
{
//TODO 交换左右子树 并将子树继续交换
temp=bt->rchild;
bt->rchild=bt->lchild;
bt->lchild=temp;
change(bt->lchild);
change(bt->rchild);
}
}
void BiTree::print(BiNode *bt) {
cout << bt->data << " ";
if (bt->lchild != NULL)
print(bt->lchild);
if (bt->rchild != NULL)
print(bt->rchild);
}
int main()
{
BiTree btree;
if(btree.Empty())
return 0;
btree.Change();
btree.Print();
return 0;
}