-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (41 loc) · 775 Bytes
/
Copy pathmain.cpp
File metadata and controls
53 lines (41 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ¶þ²æÊ÷µÄ¾µÏñ
#include <iostream>
struct BinTreeNode
{
BinTreeNode *m_lChild;
BinTreeNode *m_rChild;
char m_value;
};
BinTreeNode * CreateTree()
{
BinTreeNode *root = new BinTreeNode;
root->m_lChild = nullptr;
root->m_rChild = nullptr;
char ch;
std::cin >> ch;
if (ch != '#')
{
root->m_value = ch;
root->m_lChild = CreateTree();
root->m_rChild = CreateTree();
}
return root;
}
void Mirror(BinTreeNode *root)
{
if (!root || !(root->m_rChild && root->m_lChild))
return;
BinTreeNode *tmpNode = root->m_lChild;
root->m_lChild = root->m_rChild;
root->m_rChild = tmpNode;
if (root->m_lChild)
Mirror(root->m_lChild);
if (root->m_rChild)
Mirror(root->m_rChild);
}
int main()
{
BinTreeNode *root = CreateTree();
Mirror(root);
return 0;
}