-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
107 lines (90 loc) · 3.86 KB
/
main.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include "Static/CNodeStatic.h"
#include "Dynamic/CNodeDynamic.h"
void v_tree_test();
void v_tree_test_dynamic();
void v_print_nodes(CNodeStatic *cNodeStatic,bool isUp){
if (isUp) cNodeStatic->vPrintUp();
else cNodeStatic->vPrintAllBelow();
}
void v_print_nodes(CNodeDynamic *cNodeDynamic, bool isUp){
if (isUp) cNodeDynamic->vPrintUp();
else cNodeDynamic->vPrintAllBelow();
}
int main() {
v_tree_test();
// v_tree_test_dynamic();
return 0;
}
void v_tree_test() {
CTreeStatic treeStatic;
treeStatic.pcGetRoot()->vAddNewChild();
treeStatic.pcGetRoot()->vAddNewChild();
treeStatic.pcGetRoot()->pcGetChild(0)->vSetValue(1);
treeStatic.pcGetRoot()->pcGetChild(1)->vSetValue(2);
treeStatic.pcGetRoot()->pcGetChild(0)->vAddNewChild();
treeStatic.pcGetRoot()->pcGetChild(0)->vAddNewChild();
treeStatic.pcGetRoot()->pcGetChild(0)->pcGetChild(0)->vSetValue(11);
treeStatic.pcGetRoot()->pcGetChild(0)->pcGetChild(1)->vSetValue(12);
treeStatic.pcGetRoot()->pcGetChild(1)->vAddNewChild();
treeStatic.pcGetRoot()->pcGetChild(1)->vAddNewChild();
treeStatic.pcGetRoot()->pcGetChild(1)->pcGetChild(0)->vSetValue(21);
treeStatic.pcGetRoot()->pcGetChild(1)->pcGetChild(1)->vSetValue(22);
treeStatic.vPrintTree();
cout<<endl;
v_print_nodes(treeStatic.pcGetRoot()->pcGetChild(0),false);
// CTreeStatic treeStatic2;
// treeStatic2.pcGetRoot()->vAddNewChild();
// treeStatic2.pcGetRoot()->vAddNewChild();
// treeStatic2.pcGetRoot()->pcGetChild(0)->vSetValue(-1);
// treeStatic2.pcGetRoot()->pcGetChild(1)->vSetValue(-2);
// treeStatic2.pcGetRoot()->pcGetChild(0)->vAddNewChild();
// treeStatic2.pcGetRoot()->pcGetChild(0)->vAddNewChild();
// treeStatic2.pcGetRoot()->pcGetChild(0)->pcGetChild(0)->vSetValue(-11);
// treeStatic2.pcGetRoot()->pcGetChild(0)->pcGetChild(1)->vSetValue(-12);
//
// treeStatic2.vPrintTree();
// cout<<endl;
//
// treeStatic.bMoveSubtree(treeStatic.pcGetRoot()->pcGetChild(0)->pcGetChild(0)
// ,treeStatic2.pcGetRoot());
//
// treeStatic.vPrintTree();
// cout<<endl;
// treeStatic2.vPrintTree();
// CTreeStatic cTreeStatic(*treeStatic.pcGetRoot()->pcGetChild(0));
// cTreeStatic.vPrintTree();
}//void v_tree_test()
void v_tree_test_dynamic(){
CTreeDynamic cTreeDynamic;
cTreeDynamic.pcGetRoot()->vAddNewChild();
cTreeDynamic.pcGetRoot()->vAddNewChild();
cTreeDynamic.pcGetRoot()->pcGetChild(0)->vSetValue(1);
cTreeDynamic.pcGetRoot()->pcGetChild(1)->vSetValue(2);
cTreeDynamic.pcGetRoot()->pcGetChild(0)->vAddNewChild();
cTreeDynamic.pcGetRoot()->pcGetChild(0)->vAddNewChild();
cTreeDynamic.pcGetRoot()->pcGetChild(0)->pcGetChild(0)->vSetValue(11);
cTreeDynamic.pcGetRoot()->pcGetChild(0)->pcGetChild(1)->vSetValue(12);
cTreeDynamic.pcGetRoot()->pcGetChild(1)->vAddNewChild();
cTreeDynamic.pcGetRoot()->pcGetChild(1)->vAddNewChild();
cTreeDynamic.pcGetRoot()->pcGetChild(1)->pcGetChild(0)->vSetValue(21);
cTreeDynamic.pcGetRoot()->pcGetChild(1)->pcGetChild(1)->vSetValue(22);
cTreeDynamic.vPrintTree();
cout<<endl;
CTreeDynamic cTreeDynamic2;
cTreeDynamic2.pcGetRoot()->vAddNewChild();
cTreeDynamic2.pcGetRoot()->vAddNewChild();
cTreeDynamic2.pcGetRoot()->pcGetChild(0)->vSetValue(-1);
cTreeDynamic2.pcGetRoot()->pcGetChild(1)->vSetValue(-2);
cTreeDynamic2.pcGetRoot()->pcGetChild(0)->vAddNewChild();
cTreeDynamic2.pcGetRoot()->pcGetChild(0)->vAddNewChild();
cTreeDynamic2.pcGetRoot()->pcGetChild(0)->pcGetChild(0)->vSetValue(-11);
cTreeDynamic2.pcGetRoot()->pcGetChild(0)->pcGetChild(1)->vSetValue(-12);
cTreeDynamic2.vPrintTree();
cout<<endl;
cTreeDynamic.bMoveSubtree(cTreeDynamic.pcGetRoot()->pcGetChild(0)->pcGetChild(0)
,cTreeDynamic2.pcGetRoot()->pcGetChild(0));
cTreeDynamic.vPrintTree();
cout<<endl;
cTreeDynamic2.vPrintTree();
}