두 갈래 트리 거울--귀속법
2882 단어 ACM-반복 - 다양한 클래스 반복 방법
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define N 100
int n , m;
typedef struct node{
int data;
struct node* left;
struct node* right;
node(int _data = -1)
{
data = _data;
left = NULL;
right = NULL;
}
}Bnode;
//
void bmirror(Bnode* root)
{
if(root == NULL)
return ;
Bnode* left = root->left ;
Bnode* right = root->right;
bmirror(left);
bmirror(right);
root->left = right; //
root->right = left;
}
int main()
{
Bnode* b1 = new node(1);
Bnode* b2 = new node(2);
Bnode* b3 = new node(3);
Bnode* b4 = new node(4);
Bnode* b5 = new node(5);
Bnode* b6 = new node(6);
b1->left = b2;
b1->right = b3;
b2->left = b4;
b2->right = b5;
b3->left = b6;
/*
1 1
/ \ / \
2 3 3 2
/ \ / \ / \
4 5 6 6 5 4
*/
bmirror(b1);
return 0;
}