include iostream include vector include string using namespace std cla

 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
#include <iostream>
#include <vector>
#include <string>
using namespace::std;
class Node {
private:
string data;
Node *parent;
vector<Node*> children;
void addChildren(Node *n) {
children.push_back(n);
}
public:
Node(string d) {
data = d;
parent = NULL;
}
void setParent(Node &p) {
parent = &p;
parent->children.push_back(this);
}
void setData(string d) {
data = d;
}
size_t GetCountOfChild() {
return children.size();
}
Node *GetParent(){
return parent;
}
string GetData() {
return data;
}
vector<Node*> GetChildren() {
return children;
}
~Node() {
}
};
class TreeBeat {
private:
Node *tree;
string kurwa;
void CountResult(Node *node) {
kurwa += node->GetData();
for (size_t i = 0; i < node->GetCountOfChild(); i++) {
CountResult(node->GetChildren()[i]);
}
}
public:
TreeBeat(Node &t) {
tree = &t;
while (tree->GetParent() != NULL) {
tree = tree->GetParent();
}
kurwa = "";
}
void CountResult() {
CountResult(tree);
}
string Result() {
return kurwa;
}
};
int main() {
Node n1("c");
Node n2("d");
Node n3("*");
n1.setParent(n3);
n2.setParent(n3);
Node n4("+");
Node n5("a");
n5.setParent(n4);
n3.setParent(n4);
Node n6("=");
Node n7("b");
n7.setParent(n6);
n4.setParent(n6);
TreeBeat t(n2);
t.CountResult();
cout << t.Result();
return 0;
}