#include <stdio.h>
#include <stdlib.h>
typedef struct _BT_NODE
{
int data;
struct _BT_NODE* left;
struct _BT_NODE* right;
}BT_NODE;
BT_NODE* AppendNode(int data)
{
BT_NODE* node=(BT_NODE*)malloc(sizeof(BT_NODE));
node->left=NULL;
node->right=NULL;
node->data=data;
return node;
}
void VisitNode(BT_NODE* node)
{
printf("%d ",node->data);
}
void BinTreeMirror(BT_NODE* root)
{
BT_NODE* t;
if(root==NULL)return;
t=root->left;
root->left=root->right;
root->right=t;
BinTreeMirror(root->left);
BinTreeMirror(root->right);
}
void DFS(BT_NODE* root)
{
if(root==NULL)return;
VisitNode(root);
DFS(root->left);
DFS(root->right);
}
int main() {
BT_NODE* root;
/*
10
/\
20 30
15 16
*/
root=AppendNode(10);
root->left=AppendNode(20);
root->right=AppendNode(30);
root->left->left=AppendNode(15);
root->left->right=AppendNode(16);
printf("Original tree traversal result:\n");
DFS(root);
printf("\n");
BinTreeMirror(root);
printf("Mirror tree traversal\n");
DFS(root);
printf("\n");
return 0;
}